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 Jetblack164 · Feb 01, 2014 at 10:45 AM · movementrigidbodyvector3characters

How do I use Vector3 with rigidbody.Addforce

I am not quite sure how to phrase the question but I tried my best. Alright, I have my function to go forward, bla bla bla. The real problem I am getting from this script is the inability to move my character the direction it is pointed to. Here is my line Distance is a variable btw, rigidbody.Addforce(Vector3.forward*distance*Time.deltaTime) I have tried this aswell.. rigidbody.Addforce(Vector3(0,0,distance) and this does work except it only moves in the position that was set in the beginning, or in other words, when I rotate it, it doesn't go in the direction it is facing, any ideas on how I could, move it in the direction it is facing.

I'm a complete newbie with JavaScript and I would like to know, so I can finally get my character moving properly

Thanks in advanced :D.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Berenger · Feb 01, 2014 at 11:05 AM

Problem is Vector3 is constant of value (0, 0, 1), meaning it doesn't change, ever. That makes you move along the Z axis only. Same with Vector3(0,0,distance).

Use transform.forward instead. You'll still need a way to rotate though.

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 gfoot · Feb 01, 2014 at 11:12 AM

You should use a multiple of transform.forward, which is your object's forward vector.

You shouldn't use Time.deltaTime with forces - they are applied continuously over the course of the frame, so Unity does this multiplication for you under the hood. You also shouldn't use a distance as the magnitude of the force - they're different physical quantities. To begin with just try this:

 rigidbody.AddForce(transform.forward)

and multiply it by something if you want it to move faster/slower.

Comment
Add comment · Show 2 · 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 Jetblack164 · Feb 01, 2014 at 08:56 PM 0
Share

Thanks for the great advice (Thanks to Berenger aswell) but now I am plagued with another question XD... I tried to put "left" ins$$anonymous$$d of forward for the transform.forward part, and it seems to pause the game as if something was wrong, and I would like to know how that works? I tried making it a variable and adding 180 to it (for the backwards movement) but apparently it doesn't like that syntax either. What could I do?

avatar image Jetblack164 · Feb 02, 2014 at 11:20 AM 0
Share

Oh never $$anonymous$$d, transform.right exists :D funny scripts, could you tell me how to use "transform.up" for jumping ins$$anonymous$$d, because that doesn't work and how to limit the Velocity ( I am not sure how to use normalization).. Thanks!

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

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Should I move an object using Transform.translate, or by changing the velocity of the Rigidbody with a Vector2/3 each frame? 0 Answers

Can't move player with rigidbody.velocity 1 Answer

Change player movement 0 Answers

Npc Movement 0 Answers

Constrain character to series of intersecting paths? 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