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 Serge144 · Aug 05, 2020 at 10:22 PM · rigidbodycontrollercamera-movementplayer movement

Rigidbody movement in direction of camera?

I'm trying to make a RigidBody player move in the same direction the camera is facing. I used the good old "RigidBodyFPSWalker" script, but this makes the player move in its own forward direction and not the cameras (everytime I push up in the joystick it must go in the forward direction of the camera). How can I change the famous script in such way that i rotate the player accordingly and move in the direction of the camera? I'm guessing this RigidBodyFPSWalker is not the ideal since my game is third person :| Thanks in advance.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Llama_w_2Ls · Aug 06, 2020 at 07:44 AM

 bean.transform.rotation = Quaternion.Euler(0, transform.eulerAngles.y, 0); //Locks the y rotation of the player to the camera's y rotation
         transform.position = new Vector3 (bean.transform.position.x, bean.transform.position.y + 0.5f, bean.transform.position.z); //Moves the camera with the player

Since the rigidbody player is moving in its own direction, the only thing you have to do is rotate the player with the camera instead, so that the forward direction matches the camera's viewpoint. bean is the player and this code is attached to the main camera

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 Serge144 · Aug 06, 2020 at 09:56 AM 0
Share

hmm i was looking for something to change only on the players script.. the camera only follows the player on a fixed rotation, and is up to the user to rotate the camera with another joystick. I tried adding your first line to the player's script in Update method but doesn't work.

avatar image Llama_w_2Ls Serge144 · Aug 12, 2020 at 07:36 PM 0
Share

Sorry, this was based on the assumption that you had a camera script as well. In my camera script, the camera is parented to the player and consists of code to rotate the Player, as well as the camera. public float $$anonymous$$ouseSensitivity = 500f;

     public Transform PlayerBody;
 
     float Xrotation = 0f;
 
     public FloatingJoystick floatingJoystick;
 
     // Update is called once per frame
     public void Update()
     {
         float $$anonymous$$ouseX = floatingJoystick.Horizontal * $$anonymous$$ouseSensitivity * Time.deltaTime; //Input.GetAxis("$$anonymous$$ouse X")
         float $$anonymous$$ouseY = floatingJoystick.Vertical * $$anonymous$$ouseSensitivity * Time.deltaTime; //Input.GetAxis("$$anonymous$$ouse Y")
 
         Xrotation -= $$anonymous$$ouseY;
         Xrotation = $$anonymous$$athf.Clamp(Xrotation, -90f, 90f);
 
         transform.localRotation = Quaternion.Euler(Xrotation, 0f, 0f);
 
         PlayerBody.Rotate(Vector3.up * $$anonymous$$ouseX);
     }

Im also using the free joystick pack on the asset store for the floatingJoystick component.

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

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

Related Questions

How do I stop my player or camera from jittering during player movement? 1 Answer

Rigidbody Controller move forward in the direction of the camera 0 Answers

Laggy FPS Camera (attached to rigid body player), I have tried everything. Unity wizards need to be summoned for this one. 0 Answers

Move Character Controller 0 Answers

Issue with Instantiate and the instant that spawns on a moving object that rotates 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