Jump to content

Teleporting a car


nick.ace
 Share

Recommended Posts

I'm running into a problem where I want to manually select a location for a car to teleport to. Anyway, SetPosition() on self.entity causes weird physics glitches if the new position is too far away.

 

Is there a way to manually change positions?

 

I need cars to disappear and respawn in a city full of cars (and it's obviously impractical to put hundreds of cars in at once), so I was just going to move them, but I'm open to hearing other suggestions!

Link to comment
Share on other sites

Just tried it, but cars went crazy like before (like spinning and flying around). Maybe if I play with the setting a little I can get it to work.

 

I think part of the problem is that the vehicle part of the car actually isn't an entity. Vehicles have their own class, and although they are attached to an entity, they don't behave like most physics.

Link to comment
Share on other sites

I just tried that too, but the car body appears to get separated from the wheels and the wheels have the physics glitches as well.

 

Also, I tried releasing the car from memory, but this causes the game to crash. Apparently, vehicles cannot be released as of now, at least this seems to cause a crash.

Link to comment
Share on other sites

I believe you should disable car related physics bodies from collision before repositioning takes place, and activate it again after everything is set to new location.

That makes sense ...didn't think of that.

Threadripper 2920X Gen2 CPU(AMD 12-core 24 thread) | 32Gigs DDR4 RAM | MSI Nvidia GeForce RTX 2070 Stock OCed | ASRock X399 Professional Gaming Motherboard | Triple M.2 500Gig SSD's in Raid0

Windows 10 Pro | Blender | Paint.NetWorld Machine | Shader Map 4 | Substance Designer | Substance Painter | Inkscape | Universal Sound FX | ProBuilder | 3D World Studio | Spacescape | OpenSky | CubeMapGen | Ecrett Music | Godot Engine | Krita | Kumoworks | GDScript | Lua | Python | C# | Leadworks Engine | Unity Engine

 

Link to comment
Share on other sites

Is that done by setting mass to 0? I saw on this page that

 

If you don't want an entity to use any physics at all, set the mass to 0 with Entity::SetMass().

 

but SetMass says

 

Entities with zero mass will still collide with other objects, but will be unmovable and unresponsive to physical forces.

 

So I'm a little confused. I assume by "unmovable" it means by Physics commands, in which case the documentation should be a little more clear/specific.

  • Upvote 1
Link to comment
Share on other sites

I totally forgot how to disable physics! Thanks guys! It works pretty well, just have to find a way to prevent the car from flipping over when spawning. biggrin.png

 

Edit: After more tests, there seems to be an issue, but it can sort of be fixed with a little moving of code.

 

This is the order of commands to effectively move a vehicle:

 

self.entity:PhysicsSetPosition()
self.entity:SetMass(0)
self.entity:SetPosition()
self.entity:SetMass(1000)

 

I think that the wheels have to follow a physics object, but then get catapulted away due to the entity having mass. So if you follow this sequence of steps, you should be able to move correctly. I'm just having a problem with the y-offset right now since cars are spawning slightly below the terrain, but that should be easy to fix.

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...