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 Lazdude17 · Apr 17, 2014 at 07:20 PM · cameramovementrigidbodyrelative

Camera Relative Movement With Rigidbody.AddForce

 //Movement
 move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
 rigidbody.AddForce(move.normalized * currentSpeed);

This is my code for my players movement. I've been searching for answers to this but I can't find any that work with rigidbody.AddForce.

I just want the x and z axes of my player movement to be based on the cameras x and z, but I don't know how to do this. Pretty new to Unity and this is confusing for me since addforce is already local...

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
0

Answer by Ed unity · Apr 17, 2014 at 09:05 PM

Try adding a character controller to the Player instead of a Rigidbody and then call CharacterController.Move(move) passing in your "move" vector.

https://docs.unity3d.com/Documentation/ScriptReference/CharacterController.Move.html

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 Lazdude17 · Apr 17, 2014 at 11:05 PM

Solved it just by using this instead //Up if (Input.GetAxis("Vertical") > 0.2f) { rigidbody.AddForce(Camera.main.transform.forward * currentSpeed); }

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 Lazdude17 · Apr 18, 2014 at 07:01 PM 0
Share

But now I'm just getting cardinal directions with no interpolation...Is there a way I could fix this?`//Up if (Input.GetAxis("Vertical") > 0.2f) { move = (Camera.main.transform.forward); rigidbody.AddForce(move.normalized * currentSpeed); }

     //Down
     if (Input.GetAxis("Vertical") < -0.2f)
     {
         move = (-Camera.main.transform.forward);
         rigidbody.AddForce(move.normalized * currentSpeed);
     }

     //Left
     if (Input.GetAxis("Horizontal") < -0.2f)
     {
         move = (-Camera.main.transform.right);
         rigidbody.AddForce(move.normalized * currentSpeed);
     }

     //Right
     if (Input.GetAxis("Horizontal") > 0.2f)
     {
         move = (Camera.main.transform.right);
         rigidbody.AddForce(move.normalized * currentSpeed);
     }

     //Face Direction of $$anonymous$$ovement
     transform.LookAt(transform.position + move);`

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

21 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 avatar image

Related Questions

Move player relative to camera 0 Answers

Relative Movement Problem 1 Answer

When camera switches, rigidbody.velocity doesn't work 1 Answer

How to relative movement system based on camera direction 1 Answer

Very jerky camera movement with rigidbody 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