Old-school 2D collisions

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.

I know the game and effect you are on about, this is from my era of growing up with games. :slight_smile:

What you are after is a sliding collider, much like what happens in an FPS such as Doom or Quake when you run at a wall diagonally, you don’t instantly stop, you slide along it. Personally I wouldn’t approach this with the built-in physics system. I would only use the collision detection but not the collision response. I would handle the response myself, I doubt you will be able to easily recreate what you want without quite a bit of tweaking. If you are only doing collision in 2D you can also consider using something like the Clipper polygon library.

Thanks for the quick reply!

I haven’t heard of Clipper - I’ll look into it.

I was afraid that I’d have to roll my own collision routines… it’s not a hard thing to do for a simple game like this, but I was hoping to avoid it if possible.

The game I’m writing actually IS a remake of Sabre Wulf.
I originally remade it in 2008, for the RetroRemakes competition, but I ran out of time and didn’t quite complete it. :frowning:

It was written in Blitz3D, and indeed the built-in physics didn’t work for this type of game.
I had to write my own collision routines, and they worked very nicely.

As Sabre Wulf is my Unity “learning project”, I was hoping to find a way to do it using PhysX. Ah well… I might dig up the old B3D code and see if I can improve on it.

Never really got much further than the long strip down the bottom of the map in sabre wulf back in the day. I was crap at it.

It was indeed a very difficult game. But the atmosphere was wonderful. :slight_smile:

Solved Atic Atac, Sabrewulf and Knightlore. Never completed Alien 8 and kind of lost interest in the Ultimate game churn after that once the Stampers were no longer involved in the game designs.

I am not saying you cannot do it in PhysX, just that you will spend quite a bit of time tweaking your physics to get it “just so” especially if you are going for the authentic feel.