- Home /
Question by
unity_0WGfnyAmHiSUNw · Apr 10, 2019 at 08:41 PM ·
character controller
Does anyone know how to stop the character from rolling around?
Here Is code. Details = used a cube. speed=10 jump=5
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed;
public Rigidbody rb;
public float jumpForce;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
rb.velocity = new Vector3(Input.GetAxis("Horizontal") * moveSpeed, rb.velocity.y, Input.GetAxis("Vertical") * moveSpeed);
if (Input.GetButtonDown("Jump"))
{
rb.velocity = new Vector3(rb.velocity.x, jumpForce, rb.velocity.z);
}
}
}
Comment
Answer by stuartmcroberts · Apr 10, 2019 at 10:46 PM
You could freeze your rigidbody's rotation would stop your cube from falling over.