Jump to content

Transformation matrix


photo

Recommended Posts

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 by fred.naar
Link to comment

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()));
        

 

  • Like 1
Link to comment
  • 4 weeks later...

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 by samuel.bruner
Link to comment
×
×
  • Create New...