- Home /
Convert from javascript to c#
Hi can anyone help me convert this code from javascript to c#? I tried myself but couldn't figure out what to replace "var rotation" at the start with :/ Thanks
var rotation = Quaternion.LookRotation(Target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping);
Answer by haim96 · Mar 12, 2014 at 10:12 AM
this should work...
Quaternion rotation = Quaternion.LookRotation(Target.position - transform.position);
Answer by spraycanmansam · Mar 12, 2014 at 01:32 PM
Did you try using your quoted code as-is? The 'var' keyword in C# basically allows you to declare a variable and the compiler will determine the type from the declaration. The compiler will be able to determine the type from Quaternion.LookRotation()'s return type ...which is a Quaternion :) But of course you can always explicitly declare the variable type as haim96 answered above as well.
So basically:
var rotation = Quaternion.LookRotation(...); // annndd..
Quaternion rotation = Quaternion.LookRotation(...);
..are the same in C# :)
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Smoothly Rotate 2D sprite 90 degrees on click 2 Answers
Transform var between scripts 2 Answers
iTween Rotation not exact 0 Answers
Help, How can I get variables? 1 Answer