Page 1 of 1

two Questions?

PostPosted: Mon Jan 30, 2012 10:11 am
by master0500
1) I want to have an actor follow another actor
what i have now is
Code: Select all
angle=direction(x, y, actor.x, actor.y);
directional_velocity=5;

but when it catches up it starts vibrating, how can i stop this?

2) I need a basic enemy ship AI, i want it to move onto the screen then follow my X axis while sort of "swerving" side to side

first & best answer gets +1
-Master0500

Re: two Questions?

PostPosted: Mon Jan 30, 2012 11:56 am
by lcl
Supposing that your code is in draw actor, you can do this:
Code: Select all
angle=direction(x, y, actor.x, actor.y);
directional_velocity= 5 * (distance(x, y, actor.x, actor.y) >= 50);

Now it multiplies the 5 with 1 if if the distance is at least 50 pixels and with 0 if it's less.

Just change the 50 to what ever you want :D

You see that this thing inside the brackets returns 1 or 0 depending on the condition being true or false.
It's very handy thing to learn :D

Re: two Questions?

PostPosted: Mon Jan 30, 2012 3:04 pm
by SuperSonic
Here's another way :D
Code: Select all
if(direction(x, y, actor.x, actor.y) > angle)
{
    angle++;
}
else
{
    angle--;
}
directional_velocity = 5 * (distance(x, y, actor.x, actor.y)) >= 50;

This only diference between my code and the original is that instead of just always pointing to actor, the ship will actually steer. Plus, I also added lcl's code at the bottom :P

Re: two Questions?

PostPosted: Mon Jan 30, 2012 9:25 pm
by tintran
2) in the .ged
penemy chases actor (uses lcl's code),
enemy(child of penemy) moves side to side (relative to x-axis of penemy), set penemy to be invisible and you have enemy moving like how you described.