hello guys, it’s me again :mrgreen:
How can we rotate something just 90 degree ? I want when I press “A” my object rotate 45 degree to left and when I press “D” my object rotate 45 degree to right
Can somebody help me with that ? thanks
hello guys, it’s me again :mrgreen:
How can we rotate something just 90 degree ? I want when I press “A” my object rotate 45 degree to left and when I press “D” my object rotate 45 degree to right
Can somebody help me with that ? thanks
if press “A” then apply object.transform.localEulerAngle =new Vector3(45,0,0) or if press “D” object.transform.localEulerAngle =new Vector3(-45,0,0). This is csharp code.
Thank you. Sorry I’m new can you put Java code ?
the code posted will work in JS too.
It doesn’t work
Can you write whole code for me please ?
haha u like spoonfeeding …
try to write ur own
No I’m just really new and can’t write this code
Ok I’ve solved this problem but It isn’t what I need
I want It will move smoothly but in this code when I press “A” or “D” object move 45 degree in just one move!!!
Your not being clear.
If you want something to move smoothly, you should use Lerp, Slerp or MoveTowards. As for the amount of the move, that is up to you.
MoveTowards is great because it never moves the amount faster than speed which you suggest. Also, it ends correctly where a lerp or slerp will not.
private var target:float = 45;
public var rotationSpeed:float = 10;
function Update(){
var euler = object.transform.localEulerAngle;
if(euler.x != target){
euler.x=Math.MoveTowards(euler.x, target, rotationSpeed * Time.deltaTime);
object.transform.localEulerAngle = euler;
} else {
//check keys, change target.
}
}
Thanks a lot but when I use this code I get an error that says Unknown identifier: ‘object’ and Unknown identifier: ‘Math’
So I add this line “var object = GameObject;”
But what about ‘Math’ ?
I’m afraid but it isn’t what I need
Help please ![]()
thats what I get for leaving Unity for 4 months… been doing way too much “normal” programming
private var target:float = 45;
public var rotationSpeed:float = 10;
function Update(){
var euler = transform.localEulerAngle;
if(euler.x != target){
euler.x=Mathf.MoveTowards(euler.x, target, rotationSpeed * Time.deltaTime);
transform.localEulerAngle = euler;
} else {
//check keys, change target.
}
}
removed the “object” since it was supposed to be referencing the current game object. And Math is Mathf. (javascript and actionscript are both Math.
)
Thanks a lot again but now I get an error says
NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[ ] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[ ] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetProperty (System.Object target, System.String name)
UnityScript.Lang.UnityRuntimeServices.GetProperty (System.Object target, System.String name)
SD.Update ()
It’s long ![]()
Yes it is. Please read the documentation.
MoveObject.use.Rotation(transform, Vector3.up * 45, .5); // rotate right 45 degrees
–Eric