- Home /
help fix my script
ok so ive been converting some script a friend gave me from C# to java script, the script is suspost to give movement to rigidbody like you would do with a character controler for a racing game, im trying not to use too much of other peoples script so I can work it out for myself, this is the script
var speed = 10;
FixedUpdate(); { horizontal = Input.GetAxis("Horizontal"); vertical = Input.GetAxis("Vertical");
Vector3 a = transform.eulerAngles;
if(horizontalInput > 0.1) transform.eulerAngles = new Vector3(a.x, a.y + (value Time.Deltatime 10), a.z);
else if(horizontalInput < 0) transform.eulerAngles = new Vector3(a.x, a.y - (value Time.Deltatime 10), a.z);
Vector3 moveDirection = new Vector3(verticalInput*speed,0,0);
if(verticalInput > 0.1) rigidbody.AddRelativeForce(moveDirection,ForceMode.Acceleration); }
ok :) please help, unity does not like this line: horizontal = Input.GetAxis("Horizontal");
it complains about the "=" sign, please help!
Answer by ckfinite · Nov 15, 2010 at 12:42 AM
The problem is that you have a semi colon after FixedUpdate(). Remove it, and it should work.
You also forgot to add "function" in front of FixedUpdate().
Answer by Borgo · Jan 25, 2011 at 05:00 PM
You forget to declare the variables too...
horizontal = Input.GetAxis("Horizontal");
vertical = Input.GetAxis("Vertical");
To
var horizontal = Input.GetAxis("Horizontal");
var vertical = Input.GetAxis("Vertical");
and
if(horizontalInput > 0.1){
Where horizontalInput was declared?
Answer by Statement · Apr 02, 2011 at 05:17 PM
Where to begin? I found 13 "errors" in 14 lines of code, including scope brackets.
- You're using an integer speed variable.
- You're missing the
function
keyword. - You're having a semicolon after
function FixedUpdate()
. - You're incorrectly declaring the variables:
a
moveDirection
- You're using variables that doesn't exist:
Time.Deltatime
horizontal
vertical
horizontalInput
verticalInput
value
- You're rotating a transform where you ought to add torque to the rigidbody.
- You're applying acceleration to the right rather than forward.
I'd change the script to:
var speed = 10.0f;
function FixedUpdate() {
var horizontal = Input.GetAxis("Horizontal"); var vertical = Input.GetAxis("Vertical");
var torque = Vector3.up horizontal speed; var acceleration = Vector3.forward vertical speed;
rigidbody.AddRelativeTorque(torque); if(vertical > 0.1f) rigidbody.AddRelativeForce(acceleration, ForceMode.Acceleration); }
Your answer
Follow this Question
Related Questions
Help with a movement script. 1 Answer
AI walk through solid walls 1 Answer
Remove Force from Moving Object 1 Answer