Hey,
My player somehow is going true objects with a collider but not true the ground.
My player has a collider attached to him.
all Help is appreciated!!
using UnityEngine;
using System.Collections;
public class Player_Movement : MonoBehaviour {
public float WalkSpeed = 5.0F;
private float Walk_Speed;
public float JumpHeight = 5.0F;
private bool Grounded = true;
[Header("Speeds")]
public float FlySpeed = 20;
public float Forward = 20;
public float Runspeed = 10;
public float JumpSpeed;
[Header("Keycode")]
public KeyCode Jump;
public KeyCode Forward_W;
public KeyCode Run;
public KeyCode FlyKey;
[Header("Objects")]
public Rigidbody rb;
void Start()
{
Walk_Speed = WalkSpeed;
rb = GetComponent<Rigidbody>();
}
void Update()
{
//---------------------------------------------------------------------
//Jump
if (Grounded == true)
{
if (Input.GetKeyDown(Jump))
{
rb.velocity = new Vector3(0, JumpHeight, 0);
rb.AddForce(0, JumpSpeed, 0);
}
}
//---------------------------------------------------------------------
//Walk
float translation = Input.GetAxis("Vertical") * Walk_Speed;
float straffe = Input.GetAxis("Horizontal") * Walk_Speed;
translation *= Time.deltaTime;
straffe *= Time.deltaTime;
transform.Translate(straffe, 0, translation);
//---------------------------------------------------------------------
//Fly
if (Input.GetKey(FlyKey))
{
rb.velocity = new Vector3(0, FlySpeed, 0);
}
//---------------------------------------------------------------------
//Runing
if (Input.GetKey(Forward_W) && Input.GetKey(Run))
{
Walk_Speed = Runspeed;
}
else
{
Walk_Speed = WalkSpeed;
}
//---------------------------------------------------------------------
}
void OnCollisionExit(Collision collisionInfo)
{
Grounded = false;
}
void OnCollisionEnter(Collision collisionInfo)
{
Grounded = true;
}
public void ChangeRunSpeed(float Run)
{
Run = Runspeed;
}
public void ChangeWalkSpeed(float Walk)
{
Walk = Walk_Speed;
}
public void ChangeJumpHeight(float JumpHeightfloat)
{
JumpHeightfloat = JumpHeight;
}
}
