Hi everyone.
I want to make an infinite scroll game. For that reason I have designed a platform’s system. It moves all platforms while Player (object) is stopped. My scene is composed by 3 objects: 1 player, 1 floor and 1 obstacle.
I have tried two different ways:
-
The obstacle is moving towards my player (that is stopped). When the platform colides with the player, it is crossed. Obviously this is not the behavior that I want.
-
The Player is moving towards the obstacle (that is stopped). When the player colides with the obstacle, it isnt crossed. This is the behavior that I want.
-
The obstacles have Box Collider (without check isTrigger).
-
Player has CharacterController (but without it, he is also crossed by the platform in case 1).
-
The movement of both obstacles and player are changing Z position of the transform.
¿Any help?
Thanks in advance.

by it is crossed do you mean the objects go through each other?
if so it might not be your setup, if your moving your objects with translate and not with force or velocity objects can go through each other .
- Yeah, with “crossed” I mean an object go through another one.
What I dont understand is the reason of the different behaviors between both examples that I wrote.
Why in the first one (object moving, player stopped) the obstacle go through the player but on the other one (object stopped, player moving) player doesnt go through the obstacle?
I am not using any force neither velocity on any example.
- If I had to use force to handle my behavior, must I add rigidbody to my player and all the obstacles in my scene? And then add OnCollisionEnter to the Player?
Thanks in advance!
it must be something in the character controller that still stops the movement even though your using translate and not physics, i believe that the character controller has a built in physics system along the same lines of a rigid body so when you move it, it moves as a physics object.
if you only use translate on an object even though it has a collider it will still go through other objects, first, it needs a rigid body to detect collision, and then i would use force or velocity to actually move the object.
you won’t need OnCollisionEnter for the objects to collide, only if you want something to happen when they do
So, if I understand properly, the only way I can get the behavior that I want is by adding rigidbody to everything in the scene that I want to collide with my player.
The thing is:
If there is a lot of obstacles, platforms, items to collect that I want the player to collide with, is there any problem for adding too many rigidbody?
If you see the example image I’ve attached:
UP: If the player doesnt jump high enough to get platform2 and it crashes with it I want him (player) just to fall
DOWN: If the player crashes with the ITEM I want him to collect it, but if he crashes with the enemy I want him to die.
With that premises, if my player has no forward movement neither force nor velocity, must I have to add rigidbody to the platforms, items and enemies always and handle them in the OnCollisionEnter?
Thanks in advance
You should only need the player to have a Rigidbody, and I’m pretty sure the “Is Kinematic” checkbox needs to be checked.
The rigidbody on the player should react with the colliders on the object just fine.
For the second picture, you are going to need separate scripts for your enemies and Items, each with their own OnCollisionEnter function.
Hi Epictickle.
I have added rigidbody only to the player and first picture works properly but in my game, the second platform is like the image attached and the player cross through it. Do you have any explanation? I have add rigidbody only to the player as you said (and I tried to add also to that platform with the same result) (Remember that my player didnt move, just the whole world towards him)
Thanks in advance!
Look at platform 1 and see what the difference is between it and platform 2. Make sure that “IsTrigger” is not checked on the platform 2 collider, or you will go straight through it.
Platform2 was cloned from platform1. They only have box collider, anything more (no isTrigger checked on any of them). I think there is a bug in unity because if I change the rotation of the platform 2 exactly to the opposite inclination, player does not go through it
that is very strange… It may be because the collider on your player object is hitting the platform at just the right angle for the colliders to not respond to one another, but I doubt it… If the platform has a collider, though, the player definitely should not fall through it.
you don’t need to add colliders to everything in the scene
if you are moving the character and u want it to pick up collisions, it needs a character controller or a rigid body, the objects it runs into does NOT need rigidbodys,
if u want the box to hit the character and detect its own collision, it needs a rigidbody
I’m pretty sure at least
The thing is that I want to move ONLY platforms, not the player. The game is as follow:
- Player stopped (he is able to move left, right and jump)
- Floor is moving towards the player (to simulate the Player’s movement)
- Player is able to collide with items (and collect them), enemies (and die) and so on.
Which would be the proper configuration and the correct components that I have to add to my objects to handle the three premises?
Player: Rigidbody and Collider (anything else?) (because CharacterController doesnt work for me)
Platform: Collider, (anything else?)
Item/Enemies: (anything?)
And how can I handle the collisions? With OnCollisionEnter on the Item/Enemies?
Sorry if I am being nuisance.
Thanks a lot for your replys!
@ Pat, he will need colliders for everything that needs to detect a collision. This also means he will need colliders on his platforms. They will not, however, need a Rigidbody. Only the player should need a rigidbody.
For the enemies, and Items, I would check the IsTrigger box on their colliders, and use the OnTriggerEnter function. It’s a little more simple than working with the OnCollisionEnter function.
I am currently making a running game for the Android and iOS platforms that uses the same mechanics that your game will be using. You are more than welcome to contact me on Skype via Optix212, and I will send you my project file to review.
The thing is:
If I dont move the player (neither force or velocity), and I have a ITEM with its Collider, nothing happens. OnTrigger on Item Script doesnt shoot, neither OnCollisionEnter on Player Script :SSS
I would have to either see the project in action to know exactly what the problem is/how to fix it, or see the scripts… Or both. Have you tagged the enemies/items? It’s a lot easier to use the OnTriggerEnter if you assign a tag to them.
I have just solved the problem by adding rigidbody.addForce(some_vector) even if I dont move the player. If I comment that line, the player go through it.