Answer the question
In order to leave comments, you need to log in
How to fix a bug in Quaternion code in Unity 2.4.5?
How to fix a bug in Quaternion code in Unity 2.4.5?
I made code to make the character walk.
Wrote the code "Move":
using UnityEngine;
[RequireComponent (typeof(Rigidbody))]
public class go : MonoBehaviour
{
private Camera cam;
private Rigidbody rb;
private Vector3 velocity = Vector3.zero;
private Vector3 rotation = Vector3.zero;
private Vector3 rotationCamera = Vector3.zero;
void Start()
{
rb = GetComponent <Rigidbody> ();
cam = Camera.main;
}
public void Move (Vector3 _velocity)
{
velocity = _velocity;
}
public void Rotate(Vector3 _rotation)
{
rotation = _rotation;
}
public void RotateCam(Vector3 _rotationCam)
{
rotationCamera = _rotationCam;
}
void FixedUpdate()
{
PerformMove();
PerformRotate();
}
void PerformMove()
{
if (velocity != Vector3.zero)
{
rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);
}
}
void PerformRotate() {
rb.MoveRotation (rb.rotation + Quaternion.Euler (rotation));
if (cam != null) {
cam.transform.Rotate(-rotationCamera);
}
}
}
using UnityEngine;
[RequireComponent(typeof(go))]
public class control : MonoBehaviour {
[SerializeField]
private float speed = 5f;
[SerializeField]
private float lookspeed = 3f;
private go motor;
void Start()
{
motor = GetComponent<go>();
}
void Update() {
float xMov = Input.GetAxisRaw("Horizontal");
float zMov = Input.GetAxisRaw("Vertical");
Vector3 movHor = transform.right * xMov;
Vector3 movVer = transform.forward * zMov;
Vector3 velocity = (movHor * movVer).normalized * speed;
motor.Move(velocity);
float yRot = Input.GetAxis ("Mouse X");
Vector3 rotation = new Vector3 (of, yRot, of) * lookspeed;
motor.Rotate(rotation);
float xRot = Input.GetAxis ("Mouse Y");
Vector3 camrotation = new Vector3 (xRot, of, of) * lookpeed;
motor.Rotatecam(cam_rotation);
}
}
Answer the question
In order to leave comments, you need to log in
For what you need, there must be a method. look at the appropriate ones in
https://poqxert.ru/blog/unity/tutorials/matematika...
Perhaps in this version of the unit, not everything is so smooth. Install 2019 or 2020 version and try it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question