- Home /
Question by
Rogerb365 · Oct 10, 2019 at 03:22 PM ·
character controllercharacter movementcharacter customization
How to create an eight point 3d character controller in unity with rigidbody enabled
hi dev, i'm trying to make to make an 8-point character controller in unity. for a 3d character so far this is all I've got.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
public Rigidbody theRB;
public float moveSpeed;
Vector3 moveDir;
// Update is called once per frame
void Update()
{
moveDir.x = Input.GetAxisRaw("Horizontal");
moveDir.z = Input.GetAxisRaw("Vertical");
}
void FixedUpdate()
{
if(moveDir.x != 0 || moveDir.z != 0)
{
theRB.transform.Translate(0, 0, moveSpeed * Time.deltaTime);
}
if(moveDir.x != 0 && moveDir.z == 0)
{
theRB.transform.rotation = Quaternion.Euler(0, 90f * moveDir.x, 0);
}
else if (moveDir.x == 0 && moveDir.z != 0)
{
theRB.transform.rotation = Quaternion.Euler(0, 90f - (90f * moveDir.z), 0);
}
else if (moveDir.x != 0 && moveDir.z == 1)
{
theRB.transform.rotation = Quaternion.Euler(0, ((90f - (90f * moveDir.z)) + (45f * moveDir.x)), 0);
}
else if (moveDir.x != 0 && moveDir.z == -1)
{
theRB.transform.rotation = Quaternion.Euler(0, ((90f - (90f * moveDir.z)) + (45f * -moveDir.x)), 0);
}
}
}
Comment