|
I made an updated version of the script that was on my old post. Now all it makes the flashlight do is rotate in a circle around the x axis. the flashlight is supposed to go from (0, 0, 0) to (31, 0, 0) when sprinting, and back to (0, 0, 0) when not sprinting. Please tell me what i did wrong... again...
(comments are locked)
|
rotationX = lightObject.transform.rotation.x; this line is totally incorrect if you don't understand Quaternion's internal mechanism. instead of all these check you can do simple thing (handwrited C#-like code) Quaternion targetRotation = Quaternion.Euler(sprintActive ? 31f : 0f, 0f, 0f); this will make a rotation that your object should rotate to, rotation is already based on sprintActive value. transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, 10f * Time.deltaTime) and this will rotate your object to target rotation at maximum speed 10 deg/sec. so, finally your Update() method will looks like:
void Update()
{
Quaternion targetRotation = Quaternion.Euler(sprintActive ? 31f : 0f, 0f, 0f);
lightObject.transform.rotation = Quaternion.RotateTowards(lightObject.transform.rotation, targetRotation, 10f * Time.deltaTime)
}
and 'stopMovement' is no need actually now cause object will not rotate more then needed. unless you want to stop rotating immediately before gaining target rotation... What does the "?" do?
Aug 06 '12 at 04:49 AM
DNP
Also, What would the javascript version of: void Update() { Quaternion targetRotation = Quaternion.Euler(sprintActive ? 31f : 0f, 0f, 0f); lightObject.transform.rotation = Quaternion.RotateTowards(lightObject.transform.rotation, targetRotation, 10f * Time.deltaTime) } be?
Aug 06 '12 at 04:51 AM
DNP
Im really confused about this please explain a bit about how this works if you wouldnt mind
Aug 06 '12 at 04:52 AM
DNP
'?' is a condition symbol.
if (a > 0)
{
b = 1;
}
else
{
b = 0;
}
can be writed as b = a > 0 ? 1 : 0; about JS: i don't write in JS. it's not a lot difference between C# and JS in unity.
Aug 06 '12 at 07:41 AM
ScroodgeM
(comments are locked)
|
