How to make node to move to point in 3d space(NO animators!)

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
MessiaH
Posts: 55
Joined: Tue Jul 06, 2004 6:37 pm
Location: RUSSIA

How to make node to move to point in 3d space(NO animators!)

Post by MessiaH »

How can I make node to move to point in 3d space without animators?
All my attempts with getRotation() were useless...
Code needed...!!! :cry: :cry: :cry: [/list]
digfarenough
Posts: 39
Joined: Sat Oct 30, 2004 4:35 pm
Location: Boston, MA
Contact:

Post by digfarenough »

take a look at the thread "action every nth second"

you can do the same thing but with setPosition instead of setScale

also... why would you use getRotation to try to move a node?
MessiaH
Posts: 55
Joined: Tue Jul 06, 2004 6:37 pm
Location: RUSSIA

Post by MessiaH »

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 ..."
digfarenough
Posts: 39
Joined: Sat Oct 30, 2004 4:35 pm
Location: Boston, MA
Contact:

Post by digfarenough »

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)
Last edited by digfarenough on Wed Jan 05, 2005 8:10 pm, edited 1 time in total.
Munku
Posts: 66
Joined: Tue Nov 30, 2004 4:04 pm

Cool

Post by Munku »

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.
Umm, don't look at me that way. I'M not the dead one here.

--The One True Marshmellow
digfarenough
Posts: 39
Joined: Sat Oct 30, 2004 4:35 pm
Location: Boston, MA
Contact:

Post by digfarenough »

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)));
if speed==1 the camera will move to the target in one frame, if speed<1 it will take 1/speed frames to move there, if speed>1 the camera will overshoot the target
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));
MessiaH
Posts: 55
Joined: Tue Jul 06, 2004 6:37 pm
Location: RUSSIA

Post by MessiaH »

Thanx.
Post Reply