two Questions?

Non-platform specific questions.

two Questions?

Postby master0500 » Mon Jan 30, 2012 10:11 am

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
master0500
 
Posts: 409
Joined: Sun Jun 26, 2011 9:42 pm
Score: 27 Give a positive score

Re: two Questions?

Postby lcl » Mon Jan 30, 2012 11:56 am

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
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: two Questions?

Postby SuperSonic » Mon Jan 30, 2012 3:04 pm

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
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: two Questions?

Postby tintran » Mon Jan 30, 2012 9:25 pm

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.
Attachments
screenshot.png
enemyAI.zip
(18.58 KiB) Downloaded 72 times
User avatar
tintran
 
Posts: 157
Joined: Fri Dec 24, 2010 1:34 am
Score: 30 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest