FlyStraightAnimator (movement stuff in general)

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
scarvenger
Posts: 1
Joined: Mon Dec 04, 2006 5:16 pm

FlyStraightAnimator (movement stuff in general)

Post by scarvenger »

1)Hi, i am implementing a movement system for a RTS game, i tried to use the function createFlyStraightAnimator but i saw that the animator has to be done within a x time, is there a way to use this animator based on a speed instead of time?
2)Is there a way to know when createFlyStraightAnimator is done?I mean, a way to createFlyStraightAnimator advice me when the unit reaches its destination.
3)Lets consider that my map is a circle, i have a unit turned to the circunference of the circle at 180 degree. Then, i click in the position x of this circle, so how can i know what angle should i rotate my unit in order to him stay facing that position? (confuse question, hope you understand).
Thank you!
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

1) Yes, ever do physics at school? Remember Time = Distance/Speed? So with that you can work out what the amount of time should be depending on the required speed and you can easily work out the distance between your start and end points.

2) You'll know how long it's going to take so you could just use a timer to see if that amount of time has elapsed yet.

3) Do you mean that your unit moves around the circumference of the circle and always faces along the line of the circle? Or faces into the centre?
Image Image Image
scarvenger
Posts: 1
Joined: Mon Dec 04, 2006 5:16 pm

Post by scarvenger »

1 and 2) Thank you :)
3)How can i explain? Its a odinary situation, i have a unit standing in a place, i pick that unit and tell it to move to position x, but when the unit is moving, the unit isnt facing the place that it is going, it is facing the same place that it was facing before it started runing ex: a unit running towards a dog and looking to a cat(not just looking, but the whole body turned to the cat).
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Ahh much better explanation! Here's where i explained the same thing the other day :)

http://irrlicht.sourceforge.net/phpBB2/ ... atmatrixlh
Image Image Image
scarvenger
Posts: 1
Joined: Mon Dec 04, 2006 5:16 pm

Post by scarvenger »

it seems that it isn´t working, let´s consider that my unit is on a circle. He´s looking to 90 degrees in the circle, when i click for him to walk to 0 degree, he stays looking to 90 degree, if hes looking to 0 degree and i click to 90 degree, it will keep looking to 90, if hes looking to 180 degree and i click to continue in 180 degree, he looks at 0 degree. Got it? The explanation is litlle bit confusing again sorry.
Nox587
Posts: 12
Joined: Mon Jul 10, 2006 6:42 pm

Post by Nox587 »

It would certainly help to see some code, I don't know why JP's solution wouldn't be working for you.
scarvenger
Posts: 1
Joined: Mon Dec 04, 2006 5:16 pm

Post by scarvenger »

Code: Select all

if (device->getSceneManager()->getSceneCollisionManager()->getCollisionPoint(
			line, selector, intersection, tri))
			{
				animTargetNode->setMD2Animation(scene::EMAT_RUN);
				f64 distance = animTargetNode->getPosition().getDistanceFrom(intersection);
				intersection.Y = animTargetNode->getPosition().Y;
				f64 time = distance/0.02;
				scene::ISceneNodeAnimator* anim =
					device->getSceneManager()->createFlyStraightAnimator(animTargetNode->getPosition(),
					intersection, time, false);
				animTargetNode->addAnimator(anim);
				anim->drop();
				animTimer = device->getTimer()->getTime();
				finishAnimTimer = time + animTimer;
				matrix4 m;
				m.buildCameraLookAtMatrixLH(animTargetNode->getPosition(), 
					intersection, vector3df(0,1,0));
				animTargetNode->setRotation(m.getRotationDegrees());
}
varnie
Posts: 31
Joined: Wed Jul 19, 2006 8:27 pm
Location: Russia, Ural

Post by varnie »

hello all! i suppose it is a right place for my question, so i decided to ask this here.

could you tell me is it ok to calculate vector of movement according to current node's rotation in a way like this below (i want my node to move to new position which is achieved in accordance to its current rotation, i.e. in a direction it is looking at on this moment):

Code: Select all

  //get Node's current rotation
  core::vector3df curRotation = _caller->getRotation();
  //vector of new movement (we don't use Y coordinate here, right?) 
  core::vector3df movedir(1,0,1);
  core::matrix4 mat;
  mat.setRotationDegrees( core::vector3df( 0, curRotation.Y, 0 ) );
  mat.transformVect(movedir);
  movedir.normalize();
  //and then our final destination point will be:
  core::vector3df newPosition = movedir * ourSpeedValue * 500;

is it ok to use such code for this?

thanks for help!
varnie
Posts: 31
Joined: Wed Jul 19, 2006 8:27 pm
Location: Russia, Ural

Post by varnie »

so, is there any ideas concerning my question above?
i would be glad to see any comments!
Post Reply