• 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 /
This question was closed Mar 20, 2015 at 01:29 PM by Baste for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by drex150 · Mar 20, 2015 at 06:46 AM · transform.forward

Transform.forward is constantly changing when it shouldn't.

So I set up a script that sets the transform.forward of my player to be the same as my camera. This allows me to move the camera around but the player's controls will always work with the camera. Basically, holding up is always moving away from the camera no matter what direction the camera is facing.

The whole thing worked great. I thought I had it figured out. Then I collided with a wall. When the player collides with a wall at an angle, basically anything other than directly straight on, when I let go of my controls the player's transform.forward spins. It eventually slows down and stops. All of this shouldn't be happening because I only am setting the player's transform.forward when the left joystick is actually in use. So if you don't hold a direction, he shouldn't change his transform.forward...but he is anyway.

 if(Input.GetAxis("Horizontal") >= 0.1f || Input.GetAxis("Horizontal") <= -0.1f || Input.GetAxis("Vertical") >= 0.1f || Input.GetAxis("Vertical") <= -0.1f)
 {
     transform.forward = new Vector3 (playerCam.transform.forward.x, 0, playerCam.transform.forward.z);
 }

I have checked that it is the player's transform forward only, the camera does not change. I also checked if the controls maybe weren't getting between 0.1 and -0.1. They are getting 0 when this happens. This only happens when the joystick is between those numbers. In other words, it's happening when it actually shouldn't be. There are no other lines that modify transform.forward.

Comment
Add comment · Show 6
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 Baste · Mar 20, 2015 at 08:41 AM 0
Share

How are you moving the player? By adding force? Animation?

avatar image drex150 · Mar 20, 2015 at 09:04 AM 0
Share

I tried with force, then transform, then velocity, the same thing happens regardless of how the player is moved. I even moved him manually with the editor and as soon as he collided with the wall, he started rotating his forward.

I've also tried changing the object that it takes on the forward of, no difference, still was spinning even though the object was static and never moved.

avatar image Baste · Mar 20, 2015 at 09:34 AM 1
Share

What I'm thinking is that if your character is a cylinder (as most are), and you're moving into a wall at an angle, that will cause the character to roll along the wall, causing "spinning". That might be what you're facing.

avatar image Nymisu · Mar 20, 2015 at 10:01 AM 0
Share

You should probably try placing your character inside an empty gameobject for starters, and refer to the empty gameobject's transform when moving.

avatar image drex150 · Mar 20, 2015 at 10:16 AM 0
Share

@Baste Lol, wow, so what you said gave me an idea. I didn't have the Y rotation constrained in the rigidbody. Turned it on and the spinning stopped but I can still rotate and everything. So I guess it was building up some rotation by sliding against the wall, but since holding a direction forced the character not to rotate I didn't see it until I stopped holding a direction. I guess it build up some torque or something that didn't go away even though the character wasn't spinning until I stopped moving.

Anyway, you basically got the answer, thanks for the help.

Show more comments

0 Replies

  • Sort: 

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

22 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

Related Questions

Fire bullet in camera direction problem 3 Answers

Is there any way to translate normalized vectors into angles? 1 Answer

Rotate object around transform.forward 1 Answer

setting Transform.forward results in strange artifact 2 Answers

Eulerangles and Transform.forward... something's off? 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