var acceleration : float = 10; var deacceleration : float = 10; @HideInInspector var deaccelerationX : float; @HideInInspector var deaccelerationZ : float; var jumpVelocity : float = 400; @HideInInspector var grounded : boolean = FalseString; var maxslope : float = 60; var cameraObject : GameObject; var acceleration : float = 10; var maxSpeed : float = 25; @HideInInspector var movement : Vector2; function Update(){ movement = Vector2( rigidbody.velocity.x, rigidbody.velocity.z); if ( movement.magnitude > maxSpeed) { movement = movement.normalized; movement *= maxSpeed; } rigidbody.velocity.x = movement.x; rigidbody.velocity.z = movement.y; If (Input.GetAxis("Horizontal") == 0 && Input.GetAxis("Vertical") == 0 && grounded) { rigidbody.velocity.x = Mathf.SmoothDamp(Rigidbody.velocity.x, 0, deaccelerationX, deacceleration); rigidbody.velocity.z = Mathf.SmoothDamp(Rigidbody.velocity.z, 0, deaccelerationZ, deacceleration); } transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent(MouseLookScript).currentYRotation, 0); rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * acceleration * Time.deltaTime, 0, Input.GetAxis("Vertical") * acceleration * Time.deltaTime); if(Input.GetButtonDown("Jump") && grounded) { rigidbody.AddForce(0, jumpVelocity,0); } function OnCollisionStay(collision : Collision); { for (var contact : ContactPoint in collision.contacts) { If(Vector3.Angle(contact.normal, Vector3.up < maxSlope) grounded = true; } } function OnCollisionExit(); { grounded = false; }