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
1
Question by purecrafttube · Jul 10, 2016 at 05:20 PM · c#unity 5getaxis

Gameobject spinning by itself.

The gameobject "player" is turning around on its own axis even without and input from the mouse or keyboard. Also, it only starts turning after it has moved around the terrain and up some hills, then when i just leave the gameobject and don't input anything it starts turning. When it spins it is no particular speed in which it spins.

I also found that it spun when it slid down a hill, the larger the gradient the faster the speed of spinning.

here is my movement script;

 using UnityEngine;
 using System.Collections;
 
 public class PlayerTransport : MonoBehaviour
 {
     public Rigidbody Rigidb;
     public Animator Anim;
 
 
     int jumpCount = 0;
     bool isRunning = false;
     bool isJumpCountFull = false;
 
     public float horizontalSpeed = 1.5F;
     public float playerH;
 
     public Vector3 pos;
     public float movementSpeed;
     // Use this for initialization
     void Start()
     {
         Rigidb = GetComponent<Rigidbody>();
         Anim = GetComponent<Animator>();
         Physics.gravity = new Vector3(0, -119.0F, 0);
     }
 
     //public float rotationSpeed = 100.0F;
     void Update()
     {
 
         rotate();
         moveSpeed();
         moveAnims();
         move();
         jump();
     }
 
     void rotate()
     {
         playerH = Input.GetAxis("Mouse X") * horizontalSpeed;
         transform.Rotate(0, playerH, 0);
     }
     void move()
     {
         float translation = Input.GetAxis("Vertical") * movementSpeed;
         //float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
         translation *= Time.deltaTime;
         //rotation *= Time.deltaTime;
         transform.Translate(0, 0, translation);
         //transform.Rotate(0,playerH, 0);
     }
 
     void moveSpeed()
     {
 
 
         if (Input.GetKey(KeyCode.LeftShift))
         {
             movementSpeed = 30;
         }
         else
         {
             movementSpeed = 12;
             isRunning = false;
         }
     }
 
 
 
     void OnCollisionEnter(Collision col)
     {
         if(col.gameObject.name == "Terrain")
         {
             jumpCount = 0;
             isJumpCountFull = false;
             Debug.Log("jumps step 3");
         }
     }
    
     void jump()
     {
         if (isJumpCountFull == false)
         {
             Debug.Log("jumps step 4");
             if (Input.GetKeyDown(KeyCode.Space))
             {
                     Rigidb.AddForce(new Vector3(0, 40, 0), ForceMode.Impulse);
                     jumpCount++;
                 Debug.Log("jumps step 1");
                 
 
                if (jumpCount == 1)
                {
                     Debug.Log("jumps step 2");
                     isJumpCountFull = true;
                }
 
             }
         }
     }
 
     void moveAnims()
     {
 
 
 
         if (Input.GetKey(KeyCode.A))
         {
             Anim.Play("Walk");
         }
         else if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.W))
         {
             isRunning = true;
             Anim.Play("Run");
         }
 
         else if (Input.GetKey(KeyCode.W) && isRunning != true)
             {
 
                 Anim.Play("Walk");
 
             }
 
         else if (Input.GetKey(KeyCode.S))
         {
             Anim.Play("Walk R");
         }
 
         else if (Input.GetKey(KeyCode.D))
         {
 
             Anim.Play("Walk");
         }
 
 
 
         else
         {
             Anim.Play("Idle");
         }
     }
     
    
 }


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

Answer by purecrafttube · Jul 13, 2016 at 06:10 PM

Fixed it accedentally:

went onto Rigidbody in the editor and under the constraints section i selected freeze rotation: y

Comment
Add comment · 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
0

Answer by ReggieBeRetro · Jul 11, 2016 at 01:11 AM

I had somthing like this happen to me when i attached the script that delt with rotation of text to the parent object and not the one i wanted to. Make sure its on the right object if its parented. Just a thought. XD

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 ReggieBeRetro · Jul 11, 2016 at 04:33 AM 0
Share

sorry i meant the transform of the text not rotation.

avatar image purecrafttube ReggieBeRetro · Jul 11, 2016 at 04:19 PM 0
Share

it is attached to the correct game object but it does have a few child objects but nothing as a parent

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to use the results of a dice roll? 2 Answers

How do i Instantiate sub-Points with in Multiple Points?? 0 Answers

OnGUI will not show up? 1 Answer

My audio doesn't play, I'm through my options... 1 Answer

VS Code or visual studio? 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