• 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 airjairj · Jun 12, 2017 at 08:14 AM · movementcharactercharacter movement

How do i move my character in a direction that is not based on the character facing direction?

Example: the player is looking forward, if he press right the character goes on the right, but when he turns(180_degrees) himself if he press right the character turn left because the direction is based on where is he looking, how do I solve this?? PLS HELP!!! Here is the script: public class Player : MonoBehaviour { //Var public float movementSpeed; public GameObject camera; public Gun theGun;

 //Methods

 void Update()
 {
     //Player segue mouse
     Plane playerPlane = new Plane (Vector3.up, transform.position);
     Ray ray = UnityEngine.Camera.main.ScreenPointToRay (Input.mousePosition);
     float hitDist = 0.0f;

     if(playerPlane.Raycast(ray, out hitDist))
     {
         Vector3 targetPoint = ray.GetPoint(hitDist);
         Quaternion targetRotation = Quaternion.LookRotation (targetPoint - transform.position);
         targetRotation.x = 0;
         targetRotation.z = 0;
         transform.rotation = Quaternion.Slerp (transform.rotation, targetRotation, 7f * Time.deltaTime);
     }
     //movimenti Player
     if (Input.GetKey (KeyCode.W))
     {
         transform.Translate (Vector3.forward * movementSpeed * Time.deltaTime);


     }
     if (Input.GetKey (KeyCode.S))
     {
         transform.Translate (Vector3.back * movementSpeed * Time.deltaTime);


     }
     if (Input.GetKey (KeyCode.A))
     {
         transform.Translate (Vector3.left * movementSpeed * Time.deltaTime);


     }
     if (Input.GetKey (KeyCode.D))
     {
         transform.Translate (Vector3.right * movementSpeed * Time.deltaTime);

     }
     if (Input.GetMouseButtonDown(0))
         {
         theGun.isFiring = true;

         }
     if (Input.GetMouseButtonUp(0))
     {
         theGun.isFiring = false;
     }
     }
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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

147 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

Related Questions

Terrain Problem! Character begins to wobble extremely! 2 Answers

player getting stuck when moving. 1 Answer

Making Character Rotate 0 Answers

Why my character spread when moving? 0 Answers

How to set a start_walking animation using blentree 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges