moving NPC-Nodes like a spaceship

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
Edwart
Posts: 46
Joined: Fri Dec 30, 2005 12:29 pm

moving NPC-Nodes like a spaceship

Post by Edwart »

hi,

how can i move a node like a spaceship?

it should move vorward permanently with flying curves when the target is not straight ahead.

i use this methode to lokate the degree where i have to fly, but it changes immidietly the directon and doesnt fly a curve.

Code: Select all

core::vector3df target = playernode->getPosition();
core::vector3df pos = nodename->getPosition();
core::vector3df direction = target - pos;
r = direction.getHorizontalAngle()
//...
//and then depends the degrees:
      v.X = v.X - speed;
      v.Z= v.Z - speed; 

have you a simple example for me?

Thank you for help.

Edwart
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

maybe openSteer could be interesting for you !?!?!
look at the bottom of this side: http://abusoft.angelcities.com
there is the verry interesting flies demo and all links !!! ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
neotoma
Posts: 10
Joined: Tue Mar 29, 2005 9:49 am
Location: Germany
Contact:

Post by neotoma »

Another option could be the DustyEngine (http://www.daveandrews.org/dustyengine/).

Maybe combined with OpenSteer.... Take a look at it.

MIke
CodeDog
Posts: 106
Joined: Sat Oct 07, 2006 8:00 pm
Location: CA. USA
Contact:

Post by CodeDog »

Give each node a speed vector and add that speed vector to the nodes location each fixed time unit. You apply thrust by having an accelerate vector that you add to the speed vector each time unit if thrust is being applied.
Example:
Loc{0,0,0}
Speed{0,0,0}
Accel{0,0,0}

Create a timer thread that ticks at a fixed interval and call a timer function.

Timertick
{
Speed = Speed + Accel;
Loc = Loc + Speed;
}

ApplyThrust(vector thrust)
{
Accel = thrust;
}

Now when you give it a thrust vector the object while change speed.
And when you are not adding thrust it will coast along at a constant inerta.

Let’s walk through a few ticks.
State:
Loc{0,0,0}
Speed{0,0,0}
Accel{0,0,0}

Apply thrust vector of {0, 0 1} (and keep the thrust button down for a few ticks) just to keep it simple.

TimerTick
State:
Loc{0,0,1}
Speed{0,0,1}
Accel{0,0,1}

TimerTick
State:
Loc{0,0,3}
Speed{0,0,2}
Accel{0,0,1}

TimerTick
State:
Loc{0,0,6} //see how we are speeding up and the location is changing faster and faster
Speed{0,0,3}
Accel{0,0,1}

Thrust off
ApplyThrust(0,0,0)

TimerTick
State:
Loc{0,0,9}
Speed{0,0,3}
Accel{0,0,0}

TimerTick
State:
Loc{0,0,12} //see how we are moving at a constant inertia now
Speed{0,0,3}//notice our speed stays constant now
Accel{0,0,0}
Edwart
Posts: 46
Joined: Fri Dec 30, 2005 12:29 pm

Post by Edwart »

thanx for your help, but i dont really understand what you mean.

the movement of the spaceship is working, but not like i want...
it flyies directly to the target and do not fly curves.

how do i program that the KI should fly curves to reach the target?

this is my idea:
find out the degrees between target and npc-node.
if degree is more then 180 then rotate left (nodedegree=nodedegree+1)
if degree is less then 180 rotate right (nodedegree=nodedegree-1)
and move forward permanent in the new direction (with new degrees)

but i have no idea how to create that in a c++ code.
can you help me for that please?
CodeDog
Posts: 106
Joined: Sat Oct 07, 2006 8:00 pm
Location: CA. USA
Contact:

Post by CodeDog »

Get a vector to the target and normalize it. Use this as your thrust vector.
Each timer tick the targeted thrust vector (with a magnitude of one) will add its thrust to the inertia of the ship and the ship will appear to curve toward the target and accelerate toward it until striking it. This is how a heat seeking missile guidance system works.
Post Reply