• Kinematic Bodies
    2 replies, posted
Coming from a Unity background, I understand physics in terms of Static - which is BSP brushes I guess RigidBody - and regular physics object Kinematic - they do not receive applied forces but can inflict them. I want to be able to create the equivalent of the kinematic body. After spending a few hours experimenting and going over many documents, MOVETYPE_PUSH seems to be the answer but I can't figure out how to get it to move to inflict a push as velocity doesn't work with that move type. Best I've come up with is using ENT:Think() to self.Entity:SetPos() but that seems to teleport the thing rather than move it in a way that the physics engine can respond. Any ideas? In addition, how does parenting affect physics? It certainly acts like movetype push but other than that it doesn't seem to be documented.
[IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/PhysObj/ApplyForceCenter"]PhysObj:ApplyForceCenter[/URL] [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/PhysObj/ApplyForceOffset"]PhysObj:ApplyForceOffset[/URL] [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/PhysObj/SetVelocity"]PhysObj:SetVelocity[/URL] [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/PhysObj/SetVelocityInstantaneous"]PhysObj:SetVelocityInstantaneous[/URL] [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/PhysObj/SetInertia"]PhysObj:SetInertia[/URL] [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/PhysObj/SetDamping"]PhysObj:SetDamping[/URL] Here are some functions that might be of use but if you're going to make custom entities with certain behaviors you are better off using the Scripted Entity library.
[QUOTE=yesfish;48497022] I want to be able to create the equivalent of the kinematic body. After spending a few hours experimenting and going over many documents, MOVETYPE_PUSH seems to be the answer but I can't figure out how to get it to move to inflict a push as velocity doesn't work with that move type. [/QUOTE] MOVETYPE_PUSH is a tricky beast. Every entity that uses it calls a function named MoveLinear() or something like that, in order to move. It does several things, including setting the velocity of the object. An annoying "feature" is that if one of the variables touched by MoveLinear isn't set correctly, you won't get any movement. There is no Lua binding for MoveLinear in gmod, so you have to approximate its behavior. I forget exactly what needs to be done, but you can find a working example of MOVETYPE_PUSH in my [url=https://steamcommunity.com/sharedfiles/filedetails/?id=145310679]gmDoom Maps[/url] addon. I do recall that after setting the variable with [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetSaveValue]Entity:SetSaveValue[/url], I had to set the movetype to MOVETYPE_PUSH again, to change some c++ variable that Lua can't touch at all.
Sorry, you need to Log In to post a reply to this thread.