Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default Up direction for move_and_slide not working in 2d top-down. #84225

Open
mshka opened this issue Oct 31, 2023 · 1 comment
Open

Default Up direction for move_and_slide not working in 2d top-down. #84225

mshka opened this issue Oct 31, 2023 · 1 comment

Comments

@mshka
Copy link

mshka commented Oct 31, 2023

Godot version

3.5.3.stable.official [6c81413]

System information

Windows 10 - Godot v3.5.3.stable.official

Issue description

Description:

While updating an old project that is a 2d top-down view from Godot 3.3.4 to the latest 3.x version, which is currently 3.5.3, I encountered a change in physics behaviour. In the previous version (3.3.4), I had two kinematic bodies - one moved by an animation player, and the second moved by player input using the _physics_process and the move_and_slide method.

In Godot 3.3.4, when these two objects collided, they exhibited some friction, but the object moved by player input continued in the same direction. However, in Godot 3.5.3, when a collision occurs, movement stops from player input. 👇
ezgif com-video-to-gif

I updated the movement script so it calculates the up_direction manually since the default value Vector2(0, 0) was not working as supposed it fixed the issue of snapping but the movement is completely different and seems off

this is my code to move the player:

func _physics_process(delta):
	if is_movable():
		movement_direction_vector = controller.output
		check_if_reached_destination()
		var speed_boost = 1.0 + (player.speed_boost/100.0)
		var velocity = movement_direction_vector * MOVEMENT_SPEED * speed_boost
		move_and_slide(velocity, up_direction)

to calculate up direction:

func _physics_process(delta):
	if is_movable():
		movement_direction_vector = controller.output
		check_if_reached_destination()
		var speed_boost = 1.0 + (player.speed_boost/100.0)
		var velocity = movement_direction_vector * MOVEMENT_SPEED * speed_boost
		
		var last_collision = get_last_slide_collision()
		if last_collision:
			$CollisionMarker.global_position = last_collision.position
			var up_direction_vector = last_collision.position.direction_to(global_position)
			if abs(up_direction_vector.x) < 0.3:
				up_direction_vector.x = 0
			else:
				up_direction_vector.x = 1 * sign(up_direction_vector.x)
			
			if abs(up_direction_vector.y) < 0.3:
				up_direction_vector.y = 0
			else:
				up_direction_vector.y = 1 * sign(up_direction_vector.y)
			up_direction = Vector2(up_direction_vector.x, 0).normalized() + Vector2(0, up_direction_vector.y).normalized()
			up_direction = up_direction * UP_DIRECTION_MULTIPLIER
			print(up_direction)
		if debug_text:
			get_node(debug_text).set_text(str(up_direction))
		
		move_and_slide(velocity, up_direction)

Steps to Reproduce:

Create a project in Godot 3.5.3.
Set up two kinematic bodies, one animated and one controlled by player input.
Allow them to collide.

Expected Behavior:

In collisions, the object moved by player input should continue in the same direction with some friction, similar to Godot 3.3.4 behaviour.

Actual Behavior:

In Godot 3.5.3, when collisions occur, the object moved by player input comes to a complete stop.

Steps to reproduce

Create a project in Godot 3.5.3.
Set up two kinematic bodies, one animated and one controlled by player input.
Allow them to collide.

Minimal reproduction project

Check code from description

@mshka
Copy link
Author

mshka commented Nov 14, 2023

Just tried this in Godot 4.1.3 and it has the same issue in godot 4.x it once you set the body motion to floating it works but movement also seems off

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants