• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by kris · Nov 14, 2010 at 11:21 PM · javascriptmovementrigidbodyconvert

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, t$$anonymous$$s 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 t$$anonymous$$s line: horizontal = Input.GetAxis("Horizontal");
it complains about the "=" sign, please help!

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image

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.

Comment

People who like this

0 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ckfinite · Apr 02, 2011 at 04:26 PM 0
Share

You also forgot to add "function" in front of FixedUpdate().

avatar image

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?

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

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); }

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to make an object wait until it finishes moving? 0 Answers

Object stops but then eventually breaks through 1 Answer

Movement using rigidbody.velocity to apply a constant force until stop 1 Answer

Unity3D Ai wont shoot 1 Answer

Help with a movement script. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges