Question by
SEIFFFFFFFF · Dec 08, 2016 at 01:13 PM ·
scripting problemplayercharacter
Character goes crazy when pressing play
Hey, I m currently making a endless runner game but I bumped into a problem, I dont know how to fix. the problem is that the character goes crazy bounces,bumps into objects... anything is helpful.. thanks.
script:
using UnityEngine;
using System.Collections;
public class PlayerMotor : MonoBehaviour
{
private CharacterController controller;
private Vector3 moveVector;
private float speed = 5.0f;
private float verticalVelocity = 0.0f;
private float gravity = 5.0f;
private float animationDuration = 3.0f;
private bool isDead = false;
// Use this for initialization
void Start () {
controller = GetComponent<CharacterController> ();
}
// Update is called once per frame
void Update () {
if (isDead)
return;
if (Time.time < animationDuration) {
controller.Move (Vector3.forward * speed * Time.deltaTime);
return;
}
moveVector = Vector3.zero;
if (controller.isGrounded) {
verticalVelocity = -0.5f;
} else {
verticalVelocity -= gravity * Time.deltaTime;
}
// X - Left and Right
moveVector.x = Input.GetAxisRaw ("Horizontal") * speed;
// Y - Up and Down
moveVector.y = verticalVelocity;
// Z - Forward and Backward
moveVector.z = speed;
controller.Move (moveVector * Time.deltaTime);
}
public void SetSpeed(float modifier)
{
speed = 5.0f + modifier;
}
// It is beign called every time our capsule hits something
private void OnControllerColliderHit (ControllerColliderHit hit)
{
if (hit.point.z > transform.position.z + controller.radius)
Death ();
}
private void Death ()
{
isDead = true;
GetComponent<Score> ().OnDeath ();
}
}
Comment
What does he do when the script is disabled, because it looks rather normal to me.
Answer by SoraMahiro · Dec 08, 2016 at 06:50 PM
I would check for collider clipping or problems with your characters bone structure/rig/joints.
Your answer
![](https://koobas.hobune.stream/wayback/20220612102312im_/https://answers.unity.com/themes/thub/images/avi.jpg)