Changing collision shape for swimming

Godot 4.3 stable

I don’t know if this is the correct way to handle changing collision shapes.

I have a rectangle collision shape for my character. When I walk, run, jump, it stays the same shape. However when I swim, I want to change the shape. I used the Animation Player to change it, but that was difficult as to key in frames. I don’t really want to key in frames for changing the shape in every animation.

So when I leave the swim animation, is there an easy way to go back to the default collision shape without having to key in frames in the other animations? I have also tried to have 2 collision shapes, and I disable one and enable the other. But now I am getting stuck in walls and floors doing that.

I’m not sure what a good way to handle all of this would be.

1 Like

I think I have resolved this but if anyone has any other insights let me know. Here is a function I made to resolve sticky collisions.


# Code in my movement function

for i in get_slide_collision_count():
  var col = get_slide_collision(i)
  resolve_collision(col)


func resolve_collision(collision):
	var normal = collision.get_normal()
	var depth = collision.get_depth()
	var travel = collision.get_travel()

	# Calculate the movement needed to resolve the collision
	var move_amount = normal * depth

	# Adjust position considering the original travel direction (optional)
	global_position += move_amount + (travel * 0.1)  # Adjust the factor as needed
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.