# Collision between Player and a Wall

 0 I am trying to make a wall that the player can NOT get past. The player moves with 32 pixels per button-press, as soon as there's collision it shouldn't be able to move any further.Below is the current code, any ideas? ``````void OnTriggerEnter(Collider otherObject) { if (otherObject.tag == "walls-blocks") { Debug.Log("(PlayerHitWall) Player hit: " + otherObject.name); if (w == true) { gameObject.transform.position = lastPosition; } } } ``````By the way "w == true" refers to keyboard input booleans: ``````if (Input.GetKeyDown("w")) { w = true; s = false; a = false; d = false; } ``````and lastPosition refers to: lastPosition = gameObject.transform.position; (in the Update function) more ▼ asked Feb 06 '12 at 02:27 PM sjefke31 11 ● 10 ● 11 ● 11 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

2 answers: sort voted first
 0 What isn't working ?Basically, in those case you want tto know the penetration when the player goes where he isn't supposed to, then reject him from that amount, with a reflection upon the normal of the wall, so it don't just freeze. If your translation amount is constant, you're probably doing the right thing. more ▼ answered Feb 06 '12 at 03:18 PM Berenger 11k ● 12 ● 19 ● 53 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 Well, the problem is not really that the collision doesn't work. But the way it works in my method. The way I did it is as follows: 1) Press W 2) The player jumps up Vector3(0,0,0) to Vector3(0,0,0.64) 3) Collision detects there's another Collider 4) Due to collision it tells the player to move back: Vector3(0,0,-0.64)This doesn't go smooth, you can see the player move to the collision position and jump back. more ▼ answered Feb 06 '12 at 08:33 PM sjefke31 11 ● 10 ● 11 ● 11 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Topics:

x2482
x801
x99

asked: Feb 06 '12 at 02:27 PM

Seen: 1074 times

Last Updated: Feb 06 '12 at 08:33 PM