Hello,
I did some changes to my movement script and now my player behaves like it has no rigidbody with gravity anymore, meaning it just runs with its animations on the same spot. If I hit shift it runs under the Directional Light??
Here my code with surely some errors:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float moveSpeed = 2f;
public float jumpForce = 4f;
public float runSpeed = 5f;
Vector3 movement;
Animator anim;
Rigidbody playerRigidbody; //
void Awake ()
{
anim = GetComponent <Animator> ();
playerRigidbody = GetComponent <Rigidbody> ();
}
void Update ()
{
Idle ();
if(Input.GetKey("w"))
{
transform.Translate((Vector3.forward)* moveSpeed * Time.deltaTime);
Walk();
}
if (Input.GetKey ("w") && Input.GetKey ("left shift"))
{
transform.Translate((Vector3.forward) * runSpeed * Time.deltaTime);
Run ();
}
if(Input.GetKey("s"))
{
transform.Translate((Vector3.back)* moveSpeed * Time.deltaTime);
Walk();
}
if(Input.GetKey("a"))
{
transform.Rotate((Vector3.down)* moveSpeed * 2);
Walk();
}
if (Input.GetKey ("d")) {
transform.Rotate ((Vector3.up) * moveSpeed * 2);
Walk();
}
if (Input.GetKey ("space")&& IsGrounded())
{
Jump ();
}
}
float GroundDistance;
bool IsGrounded ()
{
return Physics.Raycast (transform.position, - Vector3.up, GroundDistance + 0.1f);
}
void Idle ()
{
anim.SetBool ("IsWalking", false);
anim.SetBool ("IsRunning", false);
}
void Walk()
{
anim.SetBool ("IsWalking", true);
}
void Run()
{
anim.SetBool ("IsRunning", true);
}
void Jump()
{
playerRigidbody.velocity = new Vector3 (0.0f, jumpForce, 0.0f);
}
}
Here is the Player moving under the Directional Light while hitting shift
guess the problem is, that it is 03:30 am