Question by
lampardiox · Nov 27, 2017 at 02:02 AM ·
rigidbodycharactercontrollermovement script
Player stuttering walking down ramps [3D]
So im trying to make a top-down game and I'm having weirds stutterings while walking off ramps and mountains.
This is my script in C#:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float speed = 4F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
private CharacterController CharCtrl;
private void Start()
{
CharCtrl = this.GetComponent<CharacterController>();
}
void Update()
{
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded)
{
Debug.Log("grounded");
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
if (moveDirection != Vector3.zero)
transform.rotation = Quaternion.LookRotation(moveDirection);
CharCtrl.Move(moveDirection / speed);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= 0;
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
}
else
{
Debug.Log("grounded");
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}
This is the problem in a gif: https://i.gyazo.com/48eebe2388735a0f0d426a63e148a435.mp4
And this is an image of the inspector of my character: http://prntscr.com/hfocmy
Thank you for reading!
Edit: Im trying using raycast but i dont figure it out... it' is hard.
Comment
Your answer
Follow this Question
Related Questions
Should i be using rigidbody or CharacterController for Controlling the player? 1 Answer
Player still move left&right in MenuUI 0 Answers
Help converting a character controller script to rigidbody 1 Answer
I can't seem to get this movement + automatic lookat the direction of movement work for a 2.5D game 0 Answers