- Home /
Why is my player clipping through walls?
Hey I'm trouble with my player clipping though walls!
Problem : My player clips though walls but also has no physics even when rigidbody attached!
Maybe Solution : I have my player stuck on one layer of Y axis so i assume i strict something to prevent it!
Image of gameplay : 
You can see that the Player is clipped through the wall (No he doesnt have a spawn issue) But you need more screenshots or a video of the stuff i did comment below!
P.S -I want the script returned of the solution you made not just tell me the problem because im very new to unity 5 and i first join on unity 4 which i had a major gap between trying unity out!
Please be sure to make it in #c but if you cant make it into javascript which is kind of hard for me use.
Here is the script!
using UnityEngine; using System.Collections;
public class Move : MonoBehaviour { bool facingRight; // Use this for initialization void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.A)) {
transform.right = new Vector3(-1, 0, 0);
facingRight = false;
}
else if (Input.GetKeyDown (KeyCode.D)) {
transform.right = new Vector3(1, 0, 0);
facingRight = true;
}
float translate = Input.GetAxis("Horizontal");
if(!facingRight)
transform.Translate (Vector3.right * -translate * 5 * Time.deltaTime);
else
transform.Translate (Vector3.right * translate * 5 * Time.deltaTime);
}
}
Okay, first of all: What are these lines:
transform.right = new Vector3(-1, 0, 0);
supposed to do? You can't just set the transform.right vector, it's only meant to be read so you get a direction vector perpendicular to transform.forward, etc.
Now about your problem. Your actor has a rigidbody; Does he have the right one? If you have a 3D environment, he needs a normal RB. If it's a 2D environment, he needs a RigidBody2D. The RB also may not be set to Is$$anonymous$$inematic = true. The actor also needs a suitable collider (BoxCollider or BoxColider2D, for example). The collider may not be set to IsTrigger = true. Similarly, the walls needs the right colliders too; Box Collider or BoxCollider2D, respectively (just an example). The wall colliders also may not be set to IsTrigger = true. Finally, The layers of both the actor and the wall objects need to be able to interact; this is set under Edit->ProjectSettings->Physics or Physics2D.
transform.right=new Vector3(-1, 0, 0); does set the direction Vector (albeit poorly since it can rotate freely among that axis). So assu$$anonymous$$g your collider is symmetrical it shouldn't be causing a problem.
$$anonymous$$ost likely the problem that you are using transform.Translate ins$$anonymous$$d of rigidbody.$$anonymous$$ovePosition. If you want objects to collide you should use rigidbody.$$anonymous$$ovePosition.
Is the rigidbody kinematic? $$anonymous$$inematic rigidbodies ignore collisions when moving.
Also, please remember to use the "101010" button to format your code.
Your answer
Follow this Question
Related Questions
Spawning Player After Player Choice. 1 Answer
Move Player to new scene without it resetting. 1 Answer
What to set to make a Instantiated prefab a collider to trigger and event? 1 Answer
Player object carried from scene to scene 1 Answer
Instantiate a prefab and follow player position in runtime? 0 Answers