- Home /
Player keeps bouncing off the walls
After many attempts at creating walls, I've finally created a player hitbox with rigidbody that collides iwth box colliders. However, instead of just stopping at the walls, they do tiny bounces off of them. Here's the video of it and my basic movement code. Remember this is all just playing around at first, not a serious attempt at a game.
#pragma strict
public var moveSpeed : float = 10f;
function Update ()
{
if(Input.GetKey(KeyCode.UpArrow))
transform.Translate(Vector3(0, 1, 0) * moveSpeed * Time.deltaTime);
if(Input.GetKey(KeyCode.DownArrow))
transform.Translate(-Vector3(0, 1, 0) * moveSpeed * Time.deltaTime);
if(Input.GetKey(KeyCode.LeftArrow))
transform.Translate(-Vector3(1, 0, 0) * moveSpeed * Time.deltaTime);
if(Input.GetKey(KeyCode.RightArrow))
transform.Translate(Vector3(1, 0, 0) * moveSpeed * Time.deltaTime);
}
Answer by aaronov · May 09, 2013 at 05:29 AM
Have you tried giving your player and the world a default physics material with a Bounciness value of 0?
I gave both the player and the wall a phsycis material with zero bounciness. The same thing still hapens
I'm actually surprised your objects are even colliding. As far as I'm aware if you translate a Rigidbody using transform.Translate() you void collision detection and the object would pass through other objects.
You might want to look into Rigidbody.$$anonymous$$ovePosition()
Answer by sammo · May 10, 2013 at 08:50 AM
try setting the player's rigidbody drag to infinity, this usually fixes similar problems to this i've encountered