- Home /
Camera/Direction Rotation
I know this probably is real noobish but I have a game where you roll a ball around using physics and I've been trying for weeks for when I rotate the camera (using the mouseOrbit script) to rotate the ball's directions. For example whenever I rotate the camera the ball still moves in the same directions and it's hard to move about. I've already tried using AddRelativeTorque which threw off the directions completely. The camera should always be facing forward in relative to the forward direction. Remember I'm using physics (AddTorque in direction).
Check if you have made the Ball object as the parent to the Camera object.
Answer by Chimera3D · Apr 26, 2012 at 12:12 AM
Answer:
var torque = Vector3(Input.GetAxis("Vertical"), 0, -Input.GetAxis("Horizontal"));
torque = Camera.main.transform.TransformDirection(torque);
torque.y = 0;
var torque2 = Vector3(-Input.GetAxis("Vertical"), Input.GetAxis("Horizontal"), 0);
torque2 = Camera.main.transform.TransformDirection(torque2);
torque2.y = 0;
Answer by maroonrs2 · Apr 24, 2012 at 04:54 AM
var xSensitivity : float;
var ySensitivity : float;
var maxHeight : float;
var minHeight : float;
private var xPos : float;
private var yPos : float;
var myTrans : Transform;
var camTrans : Transform;
function Update()
{
yPos = Mathf.Clamp(yPos - Input.GetAxis ("Mouse Y") * ySensitivity, minHeight, maxHeight);
xPos = xPos + Input.GetAxis("Mouse X") * xSensitivity;
myTrans.rotation = Quaternion.AngleAxis(xPos, Vector3.up);
camTrans.localRotation = Quaternion.AngleAxis(yPos, Vector3.right);
}
Put my Trans as your camera and the cam trans as the object you roll around. The camera should be in the ball too. Just drag and drop it in the place values and configure them. If this doesnt work then i have other worthy scripts. And the -75 was from people just -1'ing stuff. It's funny really.
That didn't work and the ball lost it's ability to rotate. :/ I'm rotating according to physics directions. i.e. forward, -forward etc.