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
0
Question by Galvin217 · Aug 25, 2016 at 07:29 PM · movementcontroller

How do I get my player to face the direction he is moving?

So I have a movement script for a 360 controller setup. Currently, it allows me to move left,right,up and down with the LeftStick. and rotate with the RightStick.

I now just want my player to move around with the LeftStick. That is, move forward and face forward..go left, face left..go right, face right..etc.

How can i edit my movement script to no longer use the RightStick to rotate and just always face the way I move with the LeftStick?

Javascript: var PlayerMovementSpeed:float = 10; var PlayerRotationSpeed:float = 110; var Ball : GameObject; var Player : GameObject; var power : float = 50;

// I seperated Movement and Button inputs into seperate functions, it makes for easier debugging function Update () { Movement(); UserInputs();

}

// This function handles the Movement calculations. // Right Thumbstick uses the 4th(Vertical) and 5th(Horizontal) Input Joystick Axes, Left Thumbstick uses the X(Horizontal) and Y(Vertical) Input Joystick Axes. // For movement the Vertical Axis is read from moving the LEFT THUMBSTICK up and down, // For Rotation I have it reading from the RIGHT THUMBSTICK. function Movement() {

 // This line is for vertical movement, right now its on the Z AXIS.
 transform.Translate(0,0,Input.GetAxis("Vertical") * Time.deltaTime * PlayerMovementSpeed);
  
 // This line is for horizontal movement, right now its on the X AXIS. When combined with vertical movement it can be used for Strafing.
 transform.Translate(Input.GetAxis("Horizontal") * Time.deltaTime * PlayerMovementSpeed,0,0);
  
 // This line is for rotation, right now its on the Y AXIS. 

Player.rigidbody.rotation = Quaternion.Euler(transform.position); }

// This function handles the Inputs from the buttons on the controller function UserInputs() { // A Button is read from Input Positive Button "joystick button 0" if(Input.GetButtonDown ("360_AButton")) { Ball.GetComponent.().AddForce( Vector3.forward * power, ForceMode.Impulse); transform.DetachChildren(); }

 // B Button is read from Input Positive Button "joystick button 1"
 if(Input.GetButtonDown ("360_BButton"))
 {
     Debug.Log("B Button!");
 }
  
 // X Button is read from Input Positive Button "joystick button 2"
 if(Input.GetButtonDown ("360_XButton"))
 {
     Debug.Log("X Button!");
 }
  
 // Y Button is read from Input Positive Button "joystick button 3"
 if(Input.GetButtonDown ("360_YButton"))
 {
     Debug.Log("Y Button!");
 }
          
 // Left Bumper is read from Input Positive Button "joystick button 4"
 if(Input.GetButtonDown ("360_LeftBumper"))
 {
     Debug.Log("Left Bumper!");
 }
  
 // Right Bumper is read from Input Positive Button "joystick button 5"
 if(Input.GetButtonDown ("360_RightBumper"))
 {
     Debug.Log("Right Bumper!");
 }
  
 // Back Button is read from Input Positive Button "joystick button 6"
 if(Input.GetButtonDown ("360_BackButton"))
 {
     Debug.Log("Back Button!");
 }
  
 // Start Button is read from Input Positive Button "joystick button 7"
 if(Input.GetButtonDown ("360_StartButton"))
 {
     Debug.Log("Start Button!");
 }
  
 // Left Thumbstick Button is read from Input Positive Button "joystick button 8"
 if(Input.GetButtonDown ("360_LeftThumbstickButton"))
 {
     Debug.Log("Left Thumbstick Button!");
 }
  
 // Right Thumbstick Button is read from Input Positive Button "joystick button 9"
 if(Input.GetButtonDown ("360_RightThumbstickButton"))
 {
     Debug.Log("Right Thumbstick Button!");
 }
  
 // Triggers are read from the 3rd Joystick Axis and read from a Sensitivity rating from -1 to 1
 //
 // Right Trigger is activated when pressure is above 0, or the dead zone.
 if(Input.GetAxis("360_Triggers")>0.001)
 {
     Debug.Log ("Right Trigger!");
 }
  
 // Right Trigger is activated when pressure is under 0, or the dead zone.
 if(Input.GetAxis("360_Triggers")<0)
 {
     Debug.Log("Left Trigger!");
 }
  
 // The D-PAD is read from the 6th(Horizontal) and 7th(Vertical) Joystick Axes and read from a Sensitivity rating from -1 to 1, similar to the Triggers.
 //
 // Right D-PAD Button is activated when pressure is above 0, or the dead zone.
 if(Input.GetAxis("360_HorizontalDPAD")>0.001)
 {
     Debug.Log ("Right D-PAD Button!");
 }
  
 // Left D-PAD Button is activated when pressure is under 0, or the dead zone.
 if(Input.GetAxis("360_HorizontalDPAD")<0)
 {
     Debug.Log("Left D-PAD Button!");
 }
  
 // Up D-PAD Button is activated when pressure is above 0, or the dead zone.
 if(Input.GetAxis("360_VerticalDPAD")>0.001)
 {
     Debug.Log ("Up D-PAD Button!");
 }
  
 // Down D-PAD Button is activated when pressure is under 0, or the dead zone.
 if(Input.GetAxis("360_VerticalDPAD")<0)
 {
     Debug.Log("Down D-PAD Button!");
 }

}

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

0 Replies

· Add your reply
  • Sort: 

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

73 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

Related Questions

Top Down Character - Face direction of movement? 0 Answers

Object Player Movement stops working after Restarting Unity 0 Answers

i need help in unity self balancing ragdoll 0 Answers

Basic MOVE and JUMP script (Jump trouble) 2 Answers

How can I get the speed of finger drag? 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