Hi,
My node is at position(0,0,0)
It is rotated so that node.Rotation.Y=45
I want it to move forward in that direction by 2
How can I do that?
Cheers
Noob: How do I move a node in a forward direction?
-
- Posts: 12
- Joined: Mon May 22, 2006 2:56 pm
-
- Posts: 12
- Joined: Mon May 22, 2006 2:56 pm
This kind of works
Code: Select all
public void Move(ISceneNode node, float speed)
{
Vector3D v = node.Position;
Vector3D r = node.Rotation;
v.X = v.X + (float)((Math.Cos(r.Y * 3.14159265 / 180) * speed));
v.Z = v.Z - (float)(Math.Sin(r.Y * 3.14159265 / 180) * speed);
node.Position = v;
}
There may be a problem with more complex movements/rotations... I prefer (with irrlicht) to use Node.AbsoluteTransformation :
Where fwdmov is a float reprensenting the amount of movement and coeff may be used for time synchronisation... (then your "speed" is equal to "fwdmov * coeff")
Code: Select all
Vector3D pos = Node.Position;
Matrix4 mat = Node.AbsoluteTransformation;
pos += new Vector3D(mat.get_M(0, 0) * fwdmov * coeff,
0,
mat.get_M(2, 0) * fwdmov * coeff);
Node.Position = pos;
Irrlicht .NET complete and Cross Platform Wrapper
The kid on my avatar wrote:A painless lesson is one without any meaning
-
- Posts: 322
- Joined: Tue Aug 30, 2005 10:34 am
- Location: slovakia
set the node as a child of camera, thus child is placed ralativly to his parent, and the parent iz the zero coordinate for that relative space. thus if you higher lover z value it will move from you, as you can see in my example here http://www.medeal.sk/irr/newstress.zip
what is this thing...