- Home /
 
               Question by 
               PanaitStudio · Feb 24, 2015 at 10:46 AM · 
                c#rigidbodyforcecontrol  
              
 
              Object move on z axis while giving force on x axis
I am using this script:
 void FixedUpdate () {
         //Move
         if(Input.GetKey(KeyCode.D)){
             input = new Vector3(65, 0, 0);
             rigidbody.AddForce(input);
         }
         if(Input.GetKey(KeyCode.A)){
             input = new Vector3(-65, 0, 0);
             rigidbody.AddForce(input);
         }
         if(Input.GetKey(KeyCode.W)){
             input = new Vector3(0, 0, 65);
             rigidbody.AddForce(input);
         }
         if(Input.GetKey(KeyCode.S)){
             input = new Vector3(0, 0, -65);
             rigidbody.AddForce(input);
         }
     }
It move my object (a cube) on the x and z axis. When I want to move the object only on an axis (like on z axis), it also moves on the x axis (same for x axis). Is my script wrong or what's happening?
               Comment
              
 
               
              please format your code so that it's not an unintelligible mess!
unless you're also pressing other keys or there's some other script applying forces/movement, this will only move on the axes you've defined.
maybe double check your rigidbody settings...
No. I am pressing the right key (only one at a time). Here's a video of what is happening and my physics setting: https://www.youtube.com/watch?v=LoUx4mID6zs 
 
                    
                   capture.png 
                   (28.1 kB) 
                  
 
                 Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                