• 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 csgeorge · Feb 03, 2017 at 12:35 AM · c#movementrigidbodyinputscene

Movement Script Only Works in One Scene

T$$anonymous$$s is the movement script I have attached to my player character prefab. In my test scene it works perfectly fine, but if I create another instance of the prefab in any other scene, the camera rotation still works, but I cannot move the character or jump at all. How can that be?

 public class Move : MonoBehaviour 
 {
     public float speed;
     public float rotationSpeed;
     public float jumpHght;
     public float grav;
     bool jumping;
     bool moving;
     public AudioClip jumpSound;
     public AudioClip landSound;
     private Rigidbody rb;
 
     //Sets variables.
     void Start()
     {
         Physics.gravity = new Vector3(0, grav, 0);
         rb = GetComponent<Rigidbody>();
     }
 
     void Update() 
     {
         //Jumps, if MagBot is not already in air.
         if(Input.GetButtonDown("Jump") && jumping == false)
         {
             rb.AddForce(new Vector3(0, jumpHght, 0), ForceMode.Impulse);
             GetComponent<AudioSource>().PlayOneShot(jumpSound);
         }
     }
 
     //Determines when MagBot is not in air.
     void OnCollisionStay(Collision collision)
     {
         jumping = false;
     }
 
     //Determines when MagBot is in air.
     void OnCollisionExit(Collision collision)
     {
         if(!jumping)
         {
             jumping = true;
         }
     }
 
     //Plays collision sound effects after landing from jump.
     void OnCollisionEnter(Collision collision)
     {
         if(collision.gameObject.tag == "Envir") 
         {
             GetComponent<AudioSource>().PlayOneShot(landSound);
         }
     }
 
     void FixedUpdate() 
     {
         //Movement variables
         float v = Input.GetAxisRaw("Vertical") * speed;
         float h = Input.GetAxisRaw("Horizontal") * speed;
         float r = Input.GetAxisRaw("Mouse X") * rotationSpeed;
         v *= Time.deltaTime;
         h *= Time.deltaTime;
         r *= Time.deltaTime;
 
         //Rotates MagBot/camera based on mouse movement.
         transform.Rotate(0, r, 0);
 
         //Moves MagBot based on WASD/Left analog stick.
         rb.AddRelativeForce(0,0,-v, ForceMode.Impulse);
         rb.AddRelativeForce(h,0,0, ForceMode.Impulse);
     }
 }
Comment
Add comment · Show 1
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 rh_galaxy · Apr 24, 2020 at 01:55 PM 0
Share

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by csgeorge · Feb 03, 2017 at 09:49 AM

Update: I've determined that t$$anonymous$$s is somehow connected to the character's animator component: when it is on, the AddRelativeForce does not work. When the animator is unchecked, it works properly. T$$anonymous$$s is however, still different from my test scene, in w$$anonymous$$ch the AddRelativeForce and animator both work together.

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 moqam · Apr 24, 2020 at 06:00 AM 0
Share
avatar image
0

Answer by FlyingHighUp · Feb 03, 2017 at 04:59 AM

It looks like t$$anonymous$$ngs are okay, your issue is likely caused by somet$$anonymous$$ng else holding your player still.

Unless... Does your rigidbody have constraints enabled on it? E.g. freezing position/rotation movements. Is the Time.deltaTime = 0? (e.g. if you set the timescale to 0 in your new scene) Are your variables set to 0? e.g. jumpHght, speed etc. Perhaps you didn't apply changes to the prefab?

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 csgeorge · Feb 03, 2017 at 08:51 AM 0
Share

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.

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

298 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 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 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

Making a bubble level (not a game but work tool) 1 Answer

How do I detect how many collisions are happening in game (for all objects in a scene?) 1 Answer

(C#) Movement Rotation Script not Working! 0 Answers

rigidbody.Addforce the force doesnt apply? 1 Answer

RigidBody.MovePosition seems jerky in movement 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