Reputation: 31
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:
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:
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?
Upvotes: 0
Views: 951
Reputation: 1334
1) Attach a box collider to the 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.
Upvotes: 0