Scripts / Rotate entity with Physics On.

Author
Message
Zigi
15
Years of Service
User Offline
Joined: 5th Jul 2009
Location:
Posted: 26th Dec 2018 17:28
Hi.

I would like to rotate an entity using Lua and also able to collide with it. But it seems like if I have the Physics On for the entity I am unable to rotate the entity and if I turn Physics Off the entity doesn't collide and I can walk through the entity.

Basically I would like to create a ramp that the player can control with switches and obviously walk up and down on the ramp. So being able to collide with it and walk on it would be essential.

Could anyone please tell me if is there any solution to this scenario?

Thanks.
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 26th Dec 2018 17:40
Yes.

CollisionOff
reposition/rotate
CollisionOn

Been there, done that, got all the T-Shirts!
PM
Zigi
15
Years of Service
User Offline
Joined: 5th Jul 2009
Location:
Posted: 26th Dec 2018 21:23
Thanks a lot. It worked
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 26th Dec 2018 21:56 Edited at: 26th Dec 2018 21:58
The thing to remember is that the visible object, i.e. the mesh + textures is a completely different animal to the physical object which is simply a collision shape.

For a simple entity like a box the two things start off life the same shape and size and as long as you move it around using the correct instructions they will stay in synch.

But the physical object is only created once when the entity is loaded, it cannot be changed. So if you use the Scale() commands for example the visible object will react and the box or whatever will look bigger but the physical object will not change.

Animated entities are a particular pita because they are effectively changing shape all the time but the collision shape will not change along with it.

Any 'active' object with physics 'on' are under the control of the physics engine, as such you cannot move them explicitly using SetPosition or whatever (it may seem to work but under the covers it is just causing chaos), instead you must disassociate them from the physics engine (i.e. with CollisionOff) before you can move them explicitly, then you can use CollisionOn to to tell the physics engine to regain control of it.
If you don't do this then effectively you have engaged in a war with the physics engine, you want the thing over here but the physics engine 'knows' it should be over there!

If you want to use real physical objects and move them properly read my thread about this (just search for physlib).
Been there, done that, got all the T-Shirts!
PM
Zigi
15
Years of Service
User Offline
Joined: 5th Jul 2009
Location:
Posted: 27th Dec 2018 11:26 Edited at: 27th Dec 2018 11:28
Thank you for the explanation I'm going to read the thread.
I have noticed the problem with the collision mesh is not updating on the fly when I was trying to use animation this is why I try to use Lua now to move things around instead
PM

Login to post a reply

Server time is: 2024-12-22 14:44:35
Your offset time is: 2024-12-22 14:44:35