- Home /
How to detect Object stuck in both wall?
I'm try to making 'moving block' in 2d platformer game.
I want to detect When an object(character) is pushed out by a 'moving block' and is trapped (or stuck) by a wall on the other side.
Is there any way other than checking if there is a collider by using raycast in both directions (ex: left and right) of the object every update()?
I'm not using rigidbody, and character object has Character Controller component. moving block is moving by change transform.posistion
Answer by MurphyMurph_21 · Nov 20, 2020 at 06:11 AM
This might work @chlgus1233 It gets the distance between 2 gameobjects. Maybe not be the best solution but it doesn't need colliders or raycast to work. In this case it gets the distance from the player and the block you want to see if its stuck. Run in the Update() method
var distanceBetween = Vector2.Distance(myPlayer.transfrom.position, blockToLookFor.transfrom.position);
Debug.Log($"distanceBetween My Player and the stuck block is : {blockToLookFor.name} == {distanceBetween}");
Your answer
![](https://koobas.hobune.stream/wayback/20220613020133im_/https://answers.unity.com/themes/thub/images/avi.jpg)