Wednesday, March 13, 2019

collision detection - Unity, changing gravity game & stopping character when he hit a wall


I am currently working on a 2d puzzle game in the unity engine. One of the aspect of this game is the possibility to rotate the level of 90°. It also rotate the gravity.


The main character is not directly controlled by the player, but instead falls when the level is rotated.


When the main character hits a wall, he should stop to moving. If I do not stop it, it kind of blinks and shakes against the wall.


To stop it I detect collision and depending on the current rotation state, the player will stop at "vertical" or "horizontal" tags when a OnCollisonEnter occurs. I must do that because when the player falls on his relative ground, he must not stop like if he had touched a wall.


My problem is the 'side' of platform, or the 'top' of wall, they use the same tag and thus do not give the correct tag to my character. I tried to put a very small invisible box on top/side of elements but the collision occurs nevertheless. It seems when the player falls and hit something he go through a bit before being replaced at correct position by unity.


Is there a way :


1 ) to not stop my character but to make it appear immobile on screen


2 ) To detect a "I cannot move anymore" collision other than by using collision?





No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...