• Alter a physics entity's angle without changing velocity?
    5 replies, posted
What I'm trying to do here is force the object's angle to match its velocity without changing its velocity without altering its velocity. As of now it seems to be the case that changing a physics entity's angle while it is in motion will alter its velocity accordingly, even if there are no forces acting on the entity. For example: [lua] function ENT:Think() self:SetAngles(self:GetVelocity():Angle()) end [/lua] One would think that this doesn't change the velocity of the entity's physics object, but it does. Being influenced by gravity in addition to its initial velocity, the entity always (eventually) assumes a downward velocity and direction. :suicide: I was wondering if one could manipulate the angle of the object using SetAngles without causing this odd behavior. Thanks for your time and effort.
You can change the rendering angles clientside in ENT:Draw(), using Entity.SetRenderAngles. That's the best solution if you're coding something like a rocket and don't need accurate physics.
[QUOTE=_Kilburn;28860730]You can change the rendering angles clientside in ENT:Draw(), using Entity.SetRenderAngles. That's the best solution if you're coding something like a rocket and don't need accurate physics.[/QUOTE] What if I do need accurate physics serverside? Is there a way to relate Entity.GetVelocity with PhysObj.AddAngleVelocity or a way to maintain the physics object's velocity while changing its angle? Thanks.
Save the velocity, set the angles, set the velocity back? or maybe disable gravity and drag on the object?
Well you should definitely not set the angles because you'd be forcing the physics engine to do something it's not supposed to, and weird shit would certainly happen, especially when the object is standing still. What do you want to do exactly? The cleanest solution would be to use the [b][url=wiki.garrysmod.com/?title=ENT.PhysicsSimulate]ENT.PhysicsSimulate [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] entity hook to apply an angle velocity to your entity so that it matches its speed. Now the whole problem is to figure out what angle velocity to apply and I really wouldn't be able to tell without testing, so you should probably play around with different values and see what happens.
[QUOTE=Fantym420;28868702]Save the velocity, set the angles, set the velocity back? or maybe disable gravity and drag on the object?[/QUOTE] The first of these worked, for anyone who's wondering. Thanks a lot for your time.
Sorry, you need to Log In to post a reply to this thread.