Wheel rotation
Can someone explain me this script? It does rotate wheel texture but i don't understand it.
I don't understand following part of the script.
wheels[0].Rotate(getCollider(0).rpm, 0 / 60 * 360 * Time.deltaTime, 0);
wheels[1].Rotate(getCollider(1).rpm, 0 / 60 * 360 * Time.deltaTime, 0);
using UnityEngine;
using System.Collections;
public class control_moped : MonoBehaviour
{
public Transform[] wheels;
}
void FixedUpdate()
{
wheels[0].Rotate(getCollider(0).rpm, 0 / 60 * 360 * Time.deltaTime, 0);
wheels[1].Rotate(getCollider(1).rpm, 0 / 60 * 360 * Time.deltaTime, 0);
}
}
Answer by kidmosey · Sep 25, 2016 at 10:15 PM
There is a lot of useless math there.
wheels[0].Rotate(getCollider(0).rpm, 0 / 60 * 360 * Time.deltaTime, 0);
wheels[1].Rotate(getCollider(1).rpm, 0 / 60 * 360 * Time.deltaTime, 0);
can be simplified as:
wheels[0].Rotate(getCollider(0).rpm, 0, 0);
wheels[1].Rotate(getCollider(1).rpm, 0, 0);
Then, you just need to check the docs to figure out what is going on.
Transform.Rotate(float xAngle, float yAngle, float zAngle)
Essentially, the wheel's xRotation is incremented by the wheel's rpm each time this is called.
Do you have any ideas why my wheel texture is rotating faster than Wheel Collider?
I have made wheel object (Wheel.fbx) using Blender.
I'm using following script to rotate wheels.
using UnityEngine;
using System.Collections;
public class control_moped : $$anonymous$$onoBehaviour
{
public Transform[] wheels;
}
void FixedUpdate()
{
wheels[0].Rotate(getCollider(0).rpm, 0, 0);
wheels[1].Rotate(getCollider(1).rpm, 0, 0);
}
}
Your answer
Follow this Question
Related Questions
How to call an action from a script that is on the anonymous object you collide with? 1 Answer
How can i restart a script on collision ? 1 Answer
Trying to Make an Interact Icon Appear 1 Answer
Destroy instatiate object on trigger enter / collision,destroy instantiate prefab on trigger enter 0 Answers
Player jumping issue 2 Answers