Question by
SickLuke23 · Mar 24, 2018 at 06:32 AM ·
axislocalglobal
How can i change from local to global axis in a rolling ball movment,How can i change from local to global axis.
So i just have a rolling ball movment script. The ball rotate in his local axis, i won t to make it rotate with global axis. How can i do it?
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class Controller : MonoBehaviour { public float speed; public float breake;
private Rigidbody rb;
private int count;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
Rigidbody rb = GetComponent<Rigidbody>();
float xSpeed = Input.GetAxis("Horizontal");
float ySpeed = Input.GetAxis("Vertical");
Vector3 movment = new Vector3(xSpeed, 0, ySpeed);
rb.AddForce(movment * speed * Time.deltaTime, ForceMode.Impulse);
rb.AddTorque(new Vector3(xSpeed, 0, ySpeed) * speed *100* Time.deltaTime);
if (Input.GetKey("space"))
{
rb.AddForce(-breake * rb.velocity);
}
} }
Comment