Parallax Collision Issue

I’m going to try and explain this as simple as possible.

I am creating a 2D style game w/ Parallaxing. I have multiple layers in order to simulate the 3D environment and everything looks great. The objects that “collide” are on the same layer.

In parallaxing, the way you simulate the 3D-ness is to keep the the player stationary and move all of the layers to simulate movement. This is the problem.

When the player moves from point 0,10,0 to 20,10,20 (the Y is fixed for the 2D) in the game, its not the player that is moving… its all of the backgrounds.

So, in reality, this is what it looks like via movement:

  • Player is stationary at 0, 10, 0
  • Layer 1 moved at normal speed and is now at -20, 0, -20
  • Layer 2 moved at a slight percentage higher than Layer 1 and its at -21, 5, -21
  • Layer 3 moved at an even higher percentage rate than Layer 2 and its at -22, 10, -22

With all of this, I have environment objects that “live” in Layer 3 but their positions are based on the Layer’s position… not the players. The objects move with the layer due to the fact that the Layer is just an empty game object that is the parent to everything that lives in that layer. I just move the empty game object’s position… nothing else.

So when a Layer 3 object collides visually with the player (they both occupy the same space) the Unity Engine’s collision detection does NOT trigger any kind of collision because neither the Player object nor the Collided-with object moved. The LAYERS did.

If the game is running and I “move” via the parallax way of doing things such that the Player object resides in the same space as a collidable object, no trigger or collision will occur. But, if I literally move either object in the Unity UI in any direction via the object’s position slider (mouse grab to increase or decrease the value)… bam! I get collision detection.

It seems as if the Unity collision detection doesnt deal w/ arbitrary object bounds so much as object movement? I really dont know any other way to describe it. And I have no idea how to solve the issue.

Any suggestions?

Thanks!

PAR

It may have more to do with Unity’s collision detection requiring a rigid body moving into a trigger, and not the other way around.

You could try making your world triggers kinematic rigid bodies to see if that helps, otherwise you might be better off rolling your own 2D collision checking, since you will get more consistent results out of it anyway.

Exactly why did you decide to move the entire world instead of just moving the character and the camera?

Thanks for the replies!

To answer Pangamini first, I am porting an engine I wrote for Cocos2d and while I have about 90% of it completed, I’m very much stuck on this collisions issue. From all my development w/ cocos2d, when dealing with a rather large “world”, the easiest and most performant thing to do was move the world and keep the player centered. Its just how it was developed. I was also using Box2D for collision detection and I didnt have to do anything fancy. It just “knew” when a spatial collision occurred between 2 objects.

With that said, since my first post here I have since changed the way movement is done and have the background stationary while moving the character. To deal w/ the parallaxing, I am moving the other layers at their respective speed relative to the player so the parallaxing is still working. I like this a bit better I think.

But now that I am moving the character, I am still having some collision issues. To get back to what FlaxSycle suggested with rigid bodies, this is my issue:

I understand the emphasis of not dealing w/ performance until you have to (at least some have suggested it) but since I am porting this over I am very aware of what the performance issues are with what I’m doing. So all of my environment objects are 2 triangle planes and the main character is a simple cube (but I will be doing a more “modeled” object for it in the near future).

To answer the unasked question of images, yes I am using SpriteManager for batching… its working pretty well so far w/ some modifications.

For all objects, I am using “mesh” colliders instead of primitive ones because I load all objects dynamically and will be getting more complex objects in as soon as I can get this collision working. So, reading up on how collisions work via the docs and referencing the collision chart, all I really need right now is a trigger collision to fire whenever the Main object hits anything.

The main character object is:

  • A cube
  • A mesh collider
  • A Rigid Body w/ “Is Kinematic” marked (since Im moving it w/ position instead of velocity)
  • Checked as Convex
  • Checked as a trigger

All other objects are:

  • 2 triangle plane
  • A mesh collider
  • Checked as a trigger

I have all collidable objects in the same “layer” for Unity’s layer collision detection along w/ the correct settings in the Physics config. I have also made sure they are absolutely at the same height.

No matter what I do, I cannot get a trigger event to occur when I get the main object in the same space as any other object UNLESS I make all objects convex. I cannot make the environment objects convex because they will sometimes overlap each other and I cannot have them “colliding” w/ each other all the time. So only the Main object can be convex.

If I take the triggers off I get nothing. If I make both the Main object and ALL other objects have rigid bodies I only get a collision to occur if the Main object is NOT kinematic.

I am so frustrated now that I am almost to the point where I will roll my own collision detection but I honestly don’t want to do that. I can see some possible uses for the physics in the future and would love to just use what Unity can do… IF I can get it working.

Thanks!

PAR

Ok after an exhaustive investigation I figured it out and it was pretty simple.

Buried in the RigidBody documentation is this little blurb:

I bit myself w/ the idea that my Main Dynamic object (the player) was to be a Mesh Collider. By forcing myself into that mantra and also refusing to have EVERYTHING as convex, I wasn’t getting the triggers to work w/ the system.

As soon as I changed the Main Dynamic object (the player) to a sphere collider, everything works the way its supposed to. Even my old “move the world and keep the player stationary” algorithm works although I think I’ll keep the new way of moving the player :slight_smile:

Anyway, thanks for the help to those that replied and if anyone else has this issue… well, there you go!

PAR