Hi all.
I’ve been messing around with Unity’s physics the last few evenings, trying to make it work like the 2D collisions of days gone by.
My apologies if some of this seems obvious or condescending - I’m just trying to be very clear about what I’m trying to achieve.
For example, on the old Spectrum game Sabre Wulf:
- when a player moves left, he moves left 1 unit per frame.
- Moving up will make him move 1 unit up per frame.
- Moving up+left will make him move 1 unit up AND 1 unit left per frame. (i.e. diagonal movement is technically faster, but it feels correct in this sort of game).
Now, that’s all fine.
What I’m having problems with is what happens when the character touches a wall in the game.
In the type of game detailed above, here’s what I’d like to happen:
- Moving up and bumping into a wall above the character should stop the character
- Moving left and bumping into a wall to the left should stop the character.
- Moving up+left and bumping into a wall on the left should have the character continue to move ONLY UP at 1 unit per frame.
- Moving up+left and bumping into a wall above should have the character continue to move ONLY LEFT at 1 unit per frame.
It’s the last 2 bits I’m having problems with.
Unity’s physics does mathematically the correct thing I guess. ie. the character pauses/recoils from the impact with the wall (so to speak), slows down a bit, and then continues sliding along the wall in the correct direction.
It’s that impact pause I want to remove.
I’ve got my character set up as a very basic rigidbody+sphere collider, with gravity off.
I’ve got the wall set up as a basic cube with box collider.
I’ve tried using the Ice physics material on both the character and the wall, but no joy.
On a related note, if I set up the wall as a trigger, and then try to process the collision in code using onTriggerEnter (to try to prevent any further movement in the direction of the wall), it doesn’t work.
onTriggerEnter is firing (checked using Debug.Log), but doesn’t stop the character going through the wall. It’s like onTriggerEnter is processed after the Update() block and it’s too late to stop the character’s movement.
Thanks for any suggestions.