- Home /
Trying to walk on a wall
I'm trying to walk on one of the walls in my game, but it always goes towards the ceiling...
BTW, rotation is the parent of the player.
Code:
public GameObject rotation;
public Rigidbody rb;
public float rbvz;
public bool update;
public float gravity;
void Start(){
rb = GetComponent<Rigidbody> ();
update = false;
gravity = 9.8f;
rbvz = rb.velocity.z;
}
//Calls update when player walks up to the wall
void OnCollisionStay(Collision other){
if(other.gameObject.name == "Cube (3)"){
update = true;
}
}
void FixedUpdate(){
if (update == true){
rotation.transform.localRotation = Quaternion.Euler(-90,0,0);
rb.useGravity = false;
rb.AddForce (0, rbvz += gravity * Time.fixedDeltaTime, 0);
}
}
Comment