Best way to move actor along a path

Hey! So I finished my A* path finder which now creates a path between start and end tiles. My question is what is the best way to move the actor along that path? Is creating custom Action an option? What is the best practice?

It depends entirely on the type of game you’re making, and the type of code you want to write. It’s really up to you. There isn’t a single best approach.

You might look into interpolation.

Interpolation doesn’t move anything - it’s just a function to smooth out a transition from points A to B.

OT: Do you want to make a simulation or an animation? In case of simulation you probably already have some kind of movement system in place in which case you just have to bake the path in somehow. If it’s a simple animation you can just move the actor along the path based on some speed.

It’s a very vague question with no good answers.

This statement contradicts itself. Once you’ve created a path (which OP has), you can use interpolation to generate points on that path over time. Transitioning from point A to B is the definition of moving something.

Nope.

Sure.

[quote=“KevinWorkman,post:4,topic:55667”]
Yes.

Maybe this’ll give u some ideas OP: http://codepen.io/hannyajin/pen/vNmzyg

This might be of interest for you: http://gamedevelopment.tutsplus.com/tutorials/understanding-steering-behaviors-path-following--gamedev-8769

[quote=“jonjava,post:5,topic:55667”]

You say that interpolation doesn’t move anything (it just transitions it from point A to B), but then you agree that transitioning from point A to B is the definition of moving something. I’m not sure what your argument is.

However, this question is pretty vague, so it’s not a very good foundation on which to argue anyway. I mentioned interpolation as something the OP can start googling. I’m not sure how you can disagree with that, but I’ll blame it on the vagueness of the question.

No, “it’s just a function to smooth out a transition from points A to B.”.

[quote=“KevinWorkman,post:7,topic:55667”]
Interpolation is sth you can use after you got movement - not before. And in the case of games you’ll probably want simulation instead of a stock animation in which case interpolation goes out the window.

I don’t. But it’s not what the OP is looking for (probably).

You can absolutely use interpolation to create movement. OP said they already have the path, they just have to move along that path. That sounds like a perfect job for interpolation.

But now we’re just repeating our arguments about a question that’s too vague to answer anyway.

Here’s how my old game did it as an example to give you some ideas. It basically just put down a bunch of hit markets that once the enemy intersects with, it moves to the next hit marker in the queue (may not be ideal):

	public void findPath(Enemy source, Entity target, int depth){
		
		Path path = pathfinder.constructPath(source, target, depth);
		
		source.clearMoveQueue();
		for(int i = 0; i < path.getSize(); i++){
			Path.Step step = path.getStep(i);
			source.queueMove(step.x*map.getTileWidth() + (map.getTileWidth()/4), step.y*map.getTileHeight() + (map.getTileHeight()/4));
		}
	}
	public void queueMove(float x, float y){
		MoveNode move = new MoveNode(x,y,8,8,this);
		move.setHitBox();
		moves.add(move);
		pathTarget = moves.get(0);
	}

In the “Enemy” update method:

				if(enablePathfinding){
					
					if(pathfindingIncrement < 0){
						
						Celeri.entityManager.findPath(this, target, 64);
						pathfindingIncrement = pathfindingRate;
						
					}
					
					// Do actual pathfinding
					if(!moves.isEmpty()){
						
						rotateTo = Tools.getRotationToFaceTarget(this, pathTarget);
						
						if(this.getHitBox().intersects(pathTarget.getHitBox())){
							pathTarget.kill(null);
							moves.remove(0);
							if(!moves.isEmpty()) pathTarget = moves.get(0);
						}
					}
					
					pathfindingIncrement -= delta;
					
				}

Edit: Forgot to mention that the Enemy moves towards the target (target might be a hit marker(MoveNode) from the path finder) by it’s rotation angle using the following:

	protected void goTowardsAngle(int delta, float angle){
		
		float dx = (float) FastTrig.sin(Math.toRadians(angle - 180));
		float dy = (float) FastTrig.cos(Math.toRadians(angle - 180));
		
		velocity.x = (speed * dx);
		velocity.y = (speed * dy);
		
	}