Goto Position

Posted By: Mysterious

Goto Position - 09/06/09 10:30

Hi
I am wondering what is the best practice to make an Entity following another movable Entity ?

thanks
Posted By: Cowabanga

Re: Goto Position - 09/06/09 18:01

Try something like this:

Code:
while(1)
{
	my.x = entity.x - 50;
	my.y = entity.y;
	my.pan = entity.pan;
}


Posted By: Fab4

Re: Goto Position - 09/06/09 18:14

I wouldn't do it this way...
calculate the distance between the two objects

sqrt(pow(player.x-my.x,2)+pow(player.y-my.y,2))


and let him look at the player.
if the distance is bigger than (for example) 20 make him move until the distance is smaller than for example 10 make him stop.

you will only have a problem with obstacles.

edit:
tell me if you need a code for this.
Posted By: DJBMASTER

Re: Goto Position - 09/06/09 18:29

Originally Posted By: Fab4
I wouldn't do it this way...
calculate the distance between the two object
sqrt(pow(player.x-my.x,2)+pow(player.y-my.y,2))


The vec_dist function does this for you.
Posted By: Mysterious

Re: Goto Position - 09/07/09 04:59

Thanks all

@Fab4
I don't care about obstacles
well, a piece of code will be nice
thanks for your time

actually I want the camera to follow the player (something like Prince of Persia camera)
© 2024 lite-C Forums