Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
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, 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!

Comment
Add comment
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
0

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
Add comment · 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
0

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
Add comment · 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
0

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
Add comment · 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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Help with a movement script. 1 Answer

AI walk through solid walls 1 Answer

Remove Force from Moving Object 1 Answer

Move RigidBody character relative to camera. 2 Answers

Rigidbody.MovePosition doesn't move reliably? 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