Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by easygaming · Mar 02, 2016 at 04:24 AM · rotationmovementrigidbodygravity

After added a rigidbody in a GameObject, it moves on rotation

I added a rigidbody to make my character stick on the ground.

However, right after I added it, the character(GameObject) moved as I rotated the screen by mouse movement.

For example, the character looks at the ground, it moves forward. If it looks at sky, it moves backward! If I do not rotate by mouse, but just move with WASD buttons, the character does not move to any direction, it just stop moving immediately when I stop pressing the key (one of WASD).

My Update() function are shown below. The rotation does not make movement of the character when I remove the rigidbody.

How can I solve this problem? Thanks for your help all the time.

 void Update() {

 // MOUSELOOK ANGLES (This makes unwanted character move)
 yaw += speedH * Input.GetAxis("Mouse X");
 pitch -= speedV * Input.GetAxis("Mouse Y");

 // TO LOOK
 transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);

 return;
 // Whatever below the line...

 // KEY MOVEMENT
 var x = Input.GetAxisRaw("Horizontal") * 0.1f;
 var z = Input.GetAxisRaw("Vertical") * 0.1f;

 // X FOR LEFT/RIGHT, Z FOR FWD/BWD
 transform.position += new Vector3(x, 0, z);
 //transform.Translate(x, 0, z); // This does not fix Y
 ...
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
Best Answer

Answer by rajavamsidhar_gvs · Mar 02, 2016 at 05:02 AM

Rigidbody>constraints>Freez positions>check X,Z. Rigidbody>constraints>Freez Rotations>check X,y,Z.

it works perfect.

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 easygaming · Mar 02, 2016 at 07:17 AM 0
Share

Thanks, it does not move anymore! But I need to learn about the reason, thanks.

avatar image rajavamsidhar_gvs · Mar 02, 2016 at 09:40 AM 0
Share

may be coz of two axis it is confused.try like this..pretty simple .,use character control for moving your object and use mouselook.cs for rotation of object.

avatar image
2

Answer by Eno-Khaon · Mar 02, 2016 at 06:44 AM

The reason this occurs is simple, but easily overlooked.

Presumably, you're looking from a first-person perspective. If you're going based on a fairly simple approach, then your character is represented as a capsule, or at least has a capsule collider.

With that in mind, consider what happens when you turn left and right: Rotate a capsule on the Y-axis and there's no obvious change to it. It's still balanced on a rounded end.

However, if you look up and down and rotate the capsule to match, what would normally happen? With the capsule tilted, it tries to fall over. That's the result when physical interactions are applied to a tilted capsule, since it's no longer perfectly balanced. However, before it visibly leans, you're correcting its rotation again in your script.

Well, when you lean forward, you're effectively falling forward onto your face, but that's canceled out by your script preventing falling forward. However, the bit of momentum going towards falling over is applied as velocity to the character.

So what's the solution, then? Well, in Unity's example first-person controller script, the left/right and up/down axes are separated. Left and right rotate the character, while up and down rotate the camera instead. That way, you look up and down without actually physically leaning forward and backward.

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 easygaming · Mar 02, 2016 at 07:19 AM 0
Share

$$anonymous$$y collider is exactly a capsule. Thanks for providing an advanced answer.

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

56 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

Related Questions

Why does the player not move around planet with gravity ? 1 Answer

Issue with Rigidbody movement one step at a time and gravity 0 Answers

How do I make my "PlayerMovement" script and "Use Gravity" checkbox (rigidbody) enable when I click SPACEBAR in game? 1 Answer

The player falls down a ladder 0 Answers

Smooth Rotation on WASD keys pressed? 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