how should I go about to do that?
Entity follow another?
hmmm for instance there is a thread where this guy talks about the entity following the mouse position in the world but what if it followed the player entity instead.
This is the code for the mouse movement follow. x = world.mouseX; y = world.mouseY;
its pretty simple to implement
and btw i played your games and my favorite one is the cave one, its pretty cool
Need to know: *Do you want to lock an Entity to another like locking an Entity to your cursor. *Or do you want an Entity to follow another from back by using “same path” with another one. *Or do you want an Entity to follow another by using target locked basic Homing Missile tech?
But, it looks like You want Entity moving towards mouse continuously? But now, need to know, do you want smooth or direct?
direct would be better in my case but isnt that just a mather of adjusting the speed?
import net.flashpunk.FP;
targetangle = FP.angle(x, y, target.x, target.y)
x += Math.cos(targetangle * FP.RAD) * customspeed * FP.elapsed;
y += Math.sin(targetangle * FP.RAD) * customspeed * FP.elapsed;
there is an angle based movement vector in this sample. so you have to change angle every moment to change the direction continuously
wait so should I put a number in the “targetangle”? and where it says “target” the type of the entity I want to follow?
package entities { import net.flashpunk.Entity; import net.flashpunk.FP; import entities.Player import net.flashpunk.utils.Input
public class collisionplatform extends Entity
{
public function collisionplatform()
{
setHitbox(50, 10);
type = "platform"
super();
}
override public function update():void
{
targetangle = FP.angle(x, y, target.x, target.y)
x += Math.cos(targetangle * FP.RAD) * 10 * FP.elapsed;
y += Math.sin(targetangle * FP.RAD) * 10 * FP.elapsed;
super.update();
}
}
}
This is what I got so far.
no, the function calculates it self. you just have to put target.x and target.y
but there is a problem here, you need to use this function in “follower”. not in platform entity.
i an kind of confused sry, the platform follows the main player, so are you saying I should make another entity called follower?
Its ok nevermind man Ill try to figure out on my own. Sryfor wasting your time… but thx:)
The way I read what you want, there could be two separate things you’re trying to do.
- Have the exact same coordinates as another entity. For this, you could just store reference to the entity you would like to ‘stick with’ and set the follower entity’s x and y to be the same as the referenced entity.
- Or, move towards another entity at a set speed. For this, you could use the FP.stepTowards(); function, or move along an angle, like what it appears you are currently trying to do. Here’s the code I use for that:
Code:
angle = FP.angle(this.x, this.y, target.x, target.y);
yVeloc = speed * Math.cos(angle * Math.PI / 180);
xVeloc = speed * Math.sin(angle * Math.PI / 180);
y -= yVeloc;
x += xVeloc;
Kk I will look this up when Im doing the AI later but for now I think if found another method
Do you use trigonometry when you do instant following too? like for instance locking an entity on another like you said at the begining.