there is an angle based movement vector in this sample. so you have to change angle every moment to change the direction continuously
Entity follow another?
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.
In programming and mathematics, n is a generic name for a given number. It can mean anything.
x = entityToFollow.x;
y = entityToFollow.y;
Could you please provide the code you used to follow to entity, i’m currently trying to follow the mouse but nothing works so far !
But if i did that, every time the player will be at the same position of the target not following, or am i wrong ?
That’s what the original topic was about. If you have something else in mind, create a new thread.