Move Player in a Game Event to specific position

Godot Version



My Character (2D sidescroller) is a simple CharacterBody2D with gravity and movement. When in a game event, I disabled inputs and want my character to go some steps in a specific direction. Let’s say I want to add to the velocity a Vector2(-400,0). Not more, not less. What is the best practice to do it?

I tried it with this function and the character is moving to the right, but the character is not stopping (also too fast, because his base speed is actual 200.

func forceMoveTo(pos: Vector2):
	velocity.x = pos.x
	direction.x = round(pos.normalized()).x

player.forceMoveTo(Vector2(-400, 0))

Has anyone an idea?

You can tween the global position of the character in this case. This will only work if you don’t need any physics detection.

1 Like