sevas55 Posted March 28 Posted March 28 (edited) I want to add force with offset to the center mass of body, lets say 1unit to X axis. public class TEst : Component { BodyRigid boat; public vec3 pos = new vec3(1,0,0);//force point void Init() { // write here code to be called on component initialization boat = node.ObjectBodyRigid; } void UpdatePhysics() { if (Input.IsKeyPressed(Input.KEY.W)) { boat.AddForce(pos, node.GetWorldDirection(MathLib.AXIS.Y)*40); } } } I suppose this shoud create rotation and translation. At the beginning when I press W key everything looks ok, but after some time body stops to rotate and his direction become ~90 degress. Rotational action not creates anymore, only translation works fine: I found here is the some kind of similar problem, but I dont understand how to use it in my case. I`ve used test example, assigned my script to cylinder and change only mass to 10 unit. Other params are default. Can anyone explain the correct way or example how to use addforce with offset. Thanks Spoiler Edited March 28 by sevas55
cash-metall Posted March 29 Posted March 29 Hello! just use WorldForce instead of Force //boat.AddForce(pos, node.GetWorldDirection(MathLib.AXIS.Y) * 50); boat.AddWorldForce(node.ToWorld(pos), node.GetWorldDirection(MathLib.AXIS.Y) * 50); For some reason, the regular addForce doesn't take into account the center of mass. I'm not sure if this is a bug or if there was some physical meaning - it needs to be checked. Thanks! 1
sevas55 Posted March 29 Author Posted March 29 (edited) Thanks for response, Alexander! Your code works correct for me. I`ve seen another users also found this function not works as local force. If possible, check AddForce function. Edited March 30 by sevas55
Recommended Posts