Thanks, problem solved guys
Did you try just directly modifying the rotation with a quaternion.euler?
something like this?
var rotationSpeedY = 50;
var rotationSpeedX = 50;
function Update () {
var RotationY : float = Input.GetAxis("Horizontal")*rotationSpeedY;
var RotationX : float = Input.GetAxis("Vertical")*rotationSpeedX;
RotationY *= Time.deltaTime;
RotationX *= Time.deltaTime;
var rotation = Quaternion.Euler(RotationY, RotationX, 0);
transform.rotation = rotation;
}
Ah sorry about that legend, I got it working and edited the post and topic. I appreciate the help anyways, though.
So now I need to know how I can see what the rotation is, so that if the X or Y rotation is more than a certain value it stops rotating.
Ah… I would just look at the code In the standard assets mouse look script for inspiration, but basically youre going to end up using some form of mathf.clamp methinks.
transform.Rotate( axis, amount );
If you want a standing character to rotate left and right, you’d use transform.Rotate( Vector3.up, rotationSpeed * Time.deltaTime )
And to see what the values are you use
transform.rotation.eulerAngles.x
Or .y, or .z
var rotationSpeedY = 50;
var rotationSpeedX = 50;
function Update () {
var RotationY : float = Input.GetAxis("Horizontal")*rotationSpeedY;
var RotationX : float = Input.GetAxis("Vertical")*rotationSpeedX*-1;
var rotation = transform.rotation.eulerAngles;
RotationY *= Time.deltaTime;
RotationX *= Time.deltaTime;
//Aim up and down
transform.Rotate(Vector3.right*RotationX);
//aim left and right
transform.Rotate(Vector3.up*RotationY, Space.World);
if(rotation.x<320 rotation.x >40 RoationX<0){transform.rotation.eulerAngles(321,rotation.y, rotation.z)}// THIS IS LINE 15 The last character is 115
Debug.Log(rotation);
Debug.Log(RotationX);
}
It says Assets/Mine/Scripts/Cannon.js(15,118): UCE0001: ‘;’ expected. Insert a semicolon at the end.
What am I doing wrong now? It should work, shouldn’t it?
Edit: Ah, I was getting all frustrated about not being able to get this to work then I realized it’s not the most important thing I need to do right now, and that it can be done later on. I still need help but I just found it funny how I wasted so much time trying to find the answer to this when it wasn’t really all that urgent. Lesson learned.
it should be
var rotationSpeedY = 50;
var rotationSpeedX = 50;
function Update () {
var RotationY : float = Input.GetAxis("Horizontal")*rotationSpeedY;
var RotationX : float = Input.GetAxis("Vertical")*rotationSpeedX*-1;
var rotation = transform.rotation.eulerAngles;
RotationY *= Time.deltaTime;
RotationX *= Time.deltaTime;
//Aim up and down
transform.Rotate(Vector3.right*RotationX);
//aim left and right
transform.Rotate(Vector3.up*RotationY, Space.World);
if(rotation.x<320 rotation.x >40 RoationX<0){transform.rotation.eulerAngles(321,rotation.y, rotation.z);}// THIS IS LINE 15 The last character is 115
Debug.Log(rotation);
Debug.Log(RotationX);
}
notice the “;” in line 15?
whoahh, I could have swore I tried that.
Also now I get a Assets/Mine/Scripts/Cannon.js(15,80): BCE0077: It is not possible to invoke an expression of type ‘UnityEngine.Vector3’.
I’m assuming that means I can’t change hte angle with that, but uhm how else would I change the angle?
You set it with an equals sign is how else. ![]()
transform.rotation is a Quaternion, which is not something you want to think about. Just know that you can’t use its members (x,y,z,w). Use transform.rotation.eulerAngles for getting or setting x, y, and z rotation, or use the handy Quaternion function s-
transform.rotation = Quaternion.Euler( rotX, rotY, rotZ );
Here is the listing for Quaternion, which shows you the functions you can use on transform.rotation (such as accessing or setting the rotation).