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 antonsimmerle · Feb 26 at 08:17 AM · game development

Player rotates immediately

Hey guys, every time when I press play in Unity, my player rotates immediately for no reason. Does someone know how I can fix that?

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 NaturedOne · Feb 26 at 08:19 AM

Sounds like you're using a rigidbody which means your character controller is interacting with the world via the physics system which is probably why it's rotating on its own.

Comment
Add comment · Show 4 · 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 antonsimmerle · Feb 26 at 08:48 AM 0
Share

Thank you very much for the answer! How do I can fix that?

avatar image NaturedOne antonsimmerle · Feb 26 at 08:52 AM 0
Share

Well, I guess it depends on what you want. You can look at the Rigid Body in the inspector and expand the "constraints" menu and then check the box that freezes Z axis rotation (if your game is 2D)

This might help you achieve the result you want.

avatar image antonsimmerle antonsimmerle · Feb 26 at 08:54 AM 0
Share

I am working on a 3D game, so the player has to turn in all four directions

avatar image NaturedOne antonsimmerle · Feb 26 at 09:23 AM 0
Share

You want to at least freeze the X and Z rotation. This will keep you character from falling over. I usually freeze the Y rotation as well, cause then the rigidbody won't rotate unexpectedly but can still be rotated via player input.

avatar image
0

Answer by antonsimmerle · Feb 26 at 09:57 AM

Now when I start the game and press a key, the player rotates, but when I press the same key again, the player stops rotating and moves like normal. Do you know why?

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 antonsimmerle · Feb 26 at 10:37 AM 0
Share

When I activate Kinematics the Movement works, but the gravity is not working. Is there a other way to prevent the player from falling over, instead of freezing the rotation?

My Movement Script:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class PlayerMovement : MonoBehaviour {

public CharacterController controller;

public float speed = 6f;

// Start is called before the first frame update void Start() {

}

 void Update()
 {
 float vertical = Input.GetAxisRaw("Vertical");
 float horizontal = Input.GetAxisRaw("Horizontal");
 Vector3 direction = new Vector3(vertical, 0f, -horizontal).normalized;

 if (direction.magnitude >= 0.1)
 {
     float targetAngle = Mathf.Atan2(direction.x, -direction.z) * Mathf.Rad2Deg;
     transform.rotation = Quaternion.Euler(0f, -targetAngle + 191f, 0f);
     controller.Move(direction * speed * Time.deltaTime);
 }


 }

}

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

133 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

Related Questions

As a game developer is it better to use Directx or OpenGL? 0 Answers

Unity 2d game 1 Answer

Is there a similar solution to UNET pay per traffic with Multiplay? 1 Answer

How generate a 2D picture puzzle from a sprite visible on game scene 1 Answer

Cannot Send Class Object From One Scene to Another 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