0

I made a 2D game using unity with custom controller script.

My player has different animations in which his collider adapt its size and offset. In his fall animation, the sprite starts with his legs bent and stretch over time to the full standing collider size.

Fall animation:

1

The problem starts when the player hits the ground in the bent state, so the animation changes to idle animation, and the collider resize to normal size, and as it suppose to happen- the player resize downwards and into the ground.

Fall animation into ground:

2

How can i move the player back up from script using the collider offset and size? How can i do this without checking the exact sizes difference and hardcoding it manually when the animation changes from fall to idle?

1 Answer 1

0

1) Attach a box collider to the ground.

  • If your ground is just an image, create a cube, remove its mesh and mesh renderer component, keeping only the box collider.
  • Resize that cube and position it to align it with your ground.

2) Make sure 'Is Trigger' on the player collider and the ground collider components checkboxes are unchecked.

This way unity physics will automatically prevent the ground and the player from ever intersecting.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.