- Home /
Object Fallow Y axis !
hey guys i was wondering if you could please help me. Basically i have two cubes one that contains my Mouselook script and one that has nothing. Now what i want to do is if the player looks up and down on the Y axis i want the other cube to fallow the up and down directions can someone please help me thank you :) I would really appreciate it.
Here is my mouse look script:
public enum RotationAxis {MouseX = 0, MouseY = 1}
var RotationAxisRotationXY = RotationAxis.MouseX | RotationAxis.MouseY;
//We are defining the variables needed for our X axis motion. This will include
//Sensitivity and the minimum and maximum of the x axis rotation
var sensitivityX : float = 400f;
var minimumX : float = -360f;
var maximumX : float = 360f;
var RotationX : float = 0f;
var OriginalRotation : Quaternion;
var Game : Transform;
// Now lets set the variables for the y axis so the player can then look up and down
// using the mouse.
var RotationY : float = 0f;
var minimumY : float = -25f;
var maximumY : float = 25;
var sensitivityY : float = 400f;
function Update () {
if(RotationAxisRotationXY == RotationAxis.MouseX){
RotationX += Input.GetAxis("Mouse X") * sensitivityX * Time.deltaTime;
RotationX = ClampAngle (RotationX, minimumX, maximumX);
OriginalRotation = XQuaternion = Quaternion.AngleAxis (RotationX , Vector3.up);
transform.localRotation = OriginalRotation * XQuaternion;
}
if(RotationAxisRotationXY == RotationAxis.MouseY){
RotationY -= Input.GetAxis ("Mouse Y") * sensitivityY * Time.deltaTime;
RotationY = ClampAngle (RotationY, minimumY, maximumY);
OriginalRotation = YQuaternion = Quaternion.AngleAxis (RotationY, Vector3.right);
transform.localRotation = OriginalRotation * YQuaternion;
}
}
static function ClampAngle (Angle, min, max): float {
if(Angle < -360){
Angle += 360;
}
if(Angle > 360){
Angle -= 360;
}
return Mathf.Clamp (Angle, min,max);
}
The variable var Game : Transform; is a reference to the cube that is meant to fallow the other cubes Y axis :) Thank you in advance :)
Answer by Anxo · Jan 07, 2012 at 04:40 PM
If you rotate Cube A up on the Y axis, you want Cube B to move up on the Y?
Place Cube B insid of Cube A, Restrict its X and Z motions and freeze its rotation.
Your answer
Follow this Question
Related Questions
Disable MouseLook for dialogues 2 Answers
Disabling a script in runtime 2 Answers
Disabling a child script within the parent. 0 Answers
How to get collisions working on a flying controller? 1 Answer
Screen go Gray and only Cursor active OnTriggerEnter 1 Answer