fred.naar Posted April 12, 2020 Share Posted April 12, 2020 (edited) Hi, I am trying to add a force to a BodyRigid in local coordinates using body.AddForce, but as I see it adds the forces in world coordinates not in local coordinates. In Unity or Unreal you can convert from local to world coordinates transform.transformdirection I tried using MathLib.Inverse4(body.Transform) but I am not getting the expected results.... I am sure it is there somewhere but I can't find it... thanks Fred Edited April 12, 2020 by fred.naar Link to comment
binstream Posted April 12, 2020 Share Posted April 12, 2020 This article might be helpful: https://developer.unigine.com/en/docs/2.11/code/fundamentals/matrix_transformations/index?rlang=cs Link to comment
fred.naar Posted April 13, 2020 Author Share Posted April 13, 2020 Thank you, I read this, it was quite useful. After some trial and error here's the way to transform a vector from local to world: vec3 wf = f*(MathLib.Inverse(node.GetWorldRotation())); 1 Link to comment
samuel.bruner Posted May 7, 2020 Share Posted May 7, 2020 (edited) This work as well // Track the player rotation in world vec3 directionx = node.GetWorldDirection(MathLib.AXIS.X); // right vector rotated to world vec3 directiony = node.GetWorldDirection(MathLib.AXIS.Y); // witch direction player is facing if (Input.IsKeyPressed(forward_key)) { node.ObjectBodyRigid.AddForce(vec3.ZERO, directiony * force_multiplier * ifps); } if (Input.IsKeyPressed(backward_key)) { node.ObjectBodyRigid.AddForce(vec3.ZERO, -directiony * force_multiplier * ifps); } if (Input.IsKeyPressed(right_key)) { node.ObjectBodyRigid.AddForce(vec3.ZERO, directionx * force_multiplier * ifps); } if (Input.IsKeyPressed(left_key)) { node.ObjectBodyRigid.AddForce(vec3.ZERO, -directionx * force_multiplier * ifps); } Edited May 7, 2020 by samuel.bruner Link to comment
Recommended Posts