How can I make node to move to point in 3d space without animators?
All my attempts with getRotation() were useless...
Code needed...!!! [/list]
How to make node to move to point in 3d space(NO animators!)
-
- Posts: 39
- Joined: Sat Oct 30, 2004 4:35 pm
- Location: Boston, MA
- Contact:
About getRotation:
The idea was that we make direct the node to our point,get vector of its direction,and every frame do something like this:
node->setPosition(node->getPosition()+node->getRotation()*speed);
To be exact, I created a camera,and wanted it to move to the point at which it looks.(Read my post "How to make camera to ..."
The idea was that we make direct the node to our point,get vector of its direction,and every frame do something like this:
node->setPosition(node->getPosition()+node->getRotation()*speed);
To be exact, I created a camera,and wanted it to move to the point at which it looks.(Read my post "How to make camera to ..."
-
- Posts: 39
- Joined: Sat Oct 30, 2004 4:35 pm
- Location: Boston, MA
- Contact:
getRotation returns the rotation of a node in euler angles so adding it to a position is meaningless
I think you want getTarget instead of getRotation
if the target of the camera has been set to the node you want to move it to (which is probably the case) then what you want is something like:
(code removed, new code will be added in a new reply below)
I think you want getTarget instead of getRotation
if the target of the camera has been set to the node you want to move it to (which is probably the case) then what you want is something like:
(code removed, new code will be added in a new reply below)
Last edited by digfarenough on Wed Jan 05, 2005 8:10 pm, edited 1 time in total.
Cool
Alright, this solves a lot that I have been trying to accomplish, however there still is a problem (which equates to a rather large problem in the whole big picture )
I am using the code as provided with a few modifications (which are nominal and don't really need to be explained because I just expanded the syntax to go over multiple lines as such:
newPos.X = currPos.X + target.X;
My actual problem is this:
I am trying to rotate backwards, which works, but the objects that should be coming at me are going away from me. When I try to make the speed negative (just adding a float to the Z) everything stops and starts to shake.
I make the float negative via: speed *= -1;
How can I fix this, and/or what would be the best way to deal with this?
Thank you, in advance.
I am using the code as provided with a few modifications (which are nominal and don't really need to be explained because I just expanded the syntax to go over multiple lines as such:
newPos.X = currPos.X + target.X;
My actual problem is this:
I am trying to rotate backwards, which works, but the objects that should be coming at me are going away from me. When I try to make the speed negative (just adding a float to the Z) everything stops and starts to shake.
I make the float negative via: speed *= -1;
How can I fix this, and/or what would be the best way to deal with this?
Thank you, in advance.
Umm, don't look at me that way. I'M not the dead one here.
--The One True Marshmellow
--The One True Marshmellow
-
- Posts: 39
- Joined: Sat Oct 30, 2004 4:35 pm
- Location: Boston, MA
- Contact:
Code: Select all
core::vector3df cameraPos = camera->getPosition();
core::vector3df targetPos = target->getPosition();
camera->setPosition(cameraPos+speed*core::vector3df((targetPos.X-cameraPos.X), (targetPos.Y-cameraPos.Y), (targetPos.Z-cameraPos.Z)));
note that overshooting can be a problem even if speed<1, so before moving the camera you should see if it's less than one frame away from hitting the target, and, if so, just move it right there
note that before I forgot to add the camera's current position to the change in position we were calculating.. that's probably what caused your weird problems
if you want the camera to move at a fixed speed (say a distance of x units per frame), we select the appropriate speed with:
speed = x/(targetPos.getDistanceFrom(cameraPos));