- Home /
simple ball rolling mechanic
okay so i need help on how to get the ball to roll when i press AD, so i fiddled around with the script for a while and the closest i got was getting no errors and finding the ball only rolled to the right unprompted.
here is the script: #pragma strict
var RotationSpeed = 100;
function Update ()
{
var rotation : float = Input.GetAxis ("Horizontal") * rotation;
Rotation *= Time.deltaTime;
UnityEngine.Rigidbody;
AddRelativeTorque (Vector3.back * rotation);
}
and at the moment im getting these errors: Assets/BallControll.js(11,2): BCE0005: Unknown identifier: 'AddRelativeTorque'.
Assets/BallControll.js(10,14): BCE0034: Expressions in statements must only be executed for their side-effects.
Assets/BallControll.js(9,2): BCE0005: Unknown identifier: 'Rotation'.
Assets/BallControll.js(8,56): BCE0005: Unknown identifier: 'rotation'.
and here is a screen shot just to give you an idea as to how this game might work
Answer by Landern · Aug 20, 2014 at 01:05 PM
well:
#pragma strict
var RotationSpeed = 100;
function Update ()
{
var rotation : float = Input.GetAxis ("Horizontal") * rotation;
Rotation *= Time.deltaTime;
UnityEngine.Rigidbody;
AddRelativeTorque (Vector3.back * rotation);
}
lets see...
var rotation : float = Input.GetAxis ("Horizontal") * rotation;
You're declaring a variable called "rotation", but you're trying to use that variable which you're declaring in the same declaration. Did you mean to use RotationSpeed?
Rotation *= Time.deltaTime;
You haven't declared a variable called Rotation, what did you mean?
UnityEngine.Rigidbody;
This is a type in the UnityEngine namespace, this does nothing. Remove it.
AddRelativeTorque (Vector3.back * rotation);
This is a method on a rigidbody, did you mean:
rigidbody.AddRelativeTorque (Vector3.back * rotation); // This applies to the rigidbody on the gameobject this script is attached to.