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 garrei · Jun 17, 2015 at 03:20 AM · cameramovementrigidbodycamera-movementlook

How to rotate a Rigidbody without rotating the gameObject?

Alright so lets keep this short n sweet.

I need to do something like the ball movement in the game Kula World, shown below (but with free mouse X,Y look movement) So when I look to the right, that automatically becomes the new "forward" direction.

Kula World Level 1 - 15

I'm still pretty new to Unity, C# and JS in general but if anyone knows how I can edit the stock import scripts for the camera movement or any other easier method to do this, the help would be much appreciated :)

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
Best Answer

Answer by duck · Jun 17, 2015 at 08:40 AM

This depends if you want the movement to be locked to one of the 6 axis directions (like kula world), or want truly free movement in any direction.

For free movement, you can use the camera's transform.forward property, and move the ball along that. If you're using physics, you could either apply a force in that direction, or if you want to apply torque you'd need to calculate the perpendicular vector to apply torque around. To do this, you'd use Vector3.Cross and feed in the camera forward vector and the relative "up" direction based on the current direction of gravity.

For movement locked to the 6 axes, you'd have to examine the values of the camera's transform.forward property and see which of the x,y,z values have the largest absolute value (Using Mathf.Abs), then convert this into a normalized vector where the largest value is given a value of 1, and the others are zeroed.

Hope this helps!

Comment
Add comment · Show 3 · 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 garrei · Jun 17, 2015 at 04:17 PM 0
Share

Thanks for the reply! I need free movement as I require the object to move around an open world but I cannot allow the player object to rotate when I rotate the camera. eg. "W" key to roll forward, look right with mouse, "W" key to roll sideways if that makes sense.. Are you saying I need to control the player movement via the camera controller? Because I have this currently as my player controller: using UnityEngine; using System.Collections;

 public class PlayerController : $$anonymous$$onoBehaviour {
 
     private Rigidbody playerRb;
     public float moveSpeed;
 
     void Start ()
     {
         playerRb = GetComponent<Rigidbody>();
     }
 
     void FixedUpdate () 
     {
         float moveHorizontal = Input.GetAxis ("Horizontal");
         float moveVertical = Input.GetAxis ("Vertical");
 
         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
 
         playerRb.AddForce (movement * moveSpeed);
     }
 }

And I have the standard import scripts for the camera controller, using just SmoothLookAt.js and $$anonymous$$ouseOrbit.js (I haven't used much JavaScript at all so I'm not sure at all how to code it into the standard scripts) :/

Hopefully its not too much to ask how I could do it? Thanks.

avatar image duck ♦♦ · Jun 18, 2015 at 09:55 AM 1
Share

You'll need to calculate "movement" like this:

 Vector3 movement = cam.forward * moveVertical + cam.right * moveHorizontal;


(where "cam" is a reference to the camera's transform)

avatar image garrei · Jun 24, 2015 at 11:08 AM 0
Share

Vector3 movement = cam.forward moveVertical + cam.right moveHorizontal;

Life saver

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Very jerky camera movement with rigidbody 1 Answer

Move RigidBody character relative to camera. 2 Answers

Rigidbody speed based on direction relative to camera 0 Answers

Moving a camera with AddFoce, or setting velocity, need help 1 Answer

How to make camera move like it does in the scene viewport? 0 Answers


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