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 /
avatar image
0
Question by XxFlyingCarrotxX · May 28, 2019 at 08:49 PM · 3rd person controller3rd person camera

How do I make a Third Person mouse Movement?

I have made a project. I am have put walking animations using Blend Tree, a 3rd person mouse look system. However, I can't seem to put an essential part of a 3rd person game. I want to be ale to freely look any direction with my mouse ( I can do that already) when i am not moving, but when the character is going forward, I want the character to move toward the direction of mouse look. So, the character should correspond and rotate to the direction the camera is facing and move in that direction. I made the mouse look,here is my script:

 public float mouseSensitivity = 10.0f;
 public Transform target;
 public float dstFromTarget = 2.0f;

 public float yaw;
 public float pitch;
 public Vector2 pitchMinMax = new Vector2(-50, 85);

 public float rotationSmoothTime = 0.02f;
 Vector3 rotationSmoothVelocity;
 Vector3 currentRotation;

 
 
  

 void LateUpdate()
 {
     //Mouse Movement
     yaw += Input.GetAxis("Mouse X") * mouseSensitivity;
     pitch -= Input.GetAxis("Mouse Y") * mouseSensitivity;

     // Claemp
     pitch = Mathf.Clamp(pitch, pitchMinMax.x, pitchMinMax.y);
    
    // Positioning
     transform.eulerAngles = currentRotation;

     transform.position = target.position - transform.forward * dstFromTarget;

     // Smoothening
     currentRotation = Vector3.SmoothDamp(currentRotation, new Vector3(pitch, yaw), ref rotationSmoothVelocity, rotationSmoothTime);


 }

}

and this is my movement Script:

 private Animator anim;
 public float speed = 3.5f;
 
 public float animspeed = 2.0f;
   

 
 
 // Start is called before the first frame update
 void Start()
 {
     anim = GetComponent<Animator>();
     
 }


 void Update()
 {
     anim.speed = animspeed;
     // Move 
     // Right, Left
     float Axis = Input.GetAxis("Horizontal") * speed;
     // Front, Back
     float translation = Input.GetAxis("Vertical") * speed;

     translation *= Time.deltaTime;
     Axis *= Time.deltaTime;
     transform.Translate(Axis, 0, 0);
     transform.Translate(0, 0, translation);

     // blend tree shit i dont undertsand
     var x = Input.GetAxis("Horizontal") * speed;
     
     var y = Input.GetAxis("Vertical") * speed;
     Move(x, y);
    
 }

     private void Move(float x,float y)
     {
         anim.SetFloat("VelX", x )  ;
         anim.SetFloat("VelY", y  ) ;    
     }
     
 

}

Pls help.

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

107 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

Related Questions

How to move 3rd person controller in camera's local space? 0 Answers

Characters are not behaving. 0 Answers

Controlling a 3rd Person 2D Sprite in a 3D Environment 0 Answers

How to make the character move and rotate where the camera is facing (3rd person) 0 Answers

How to get JUST the y rotation of an object? 3 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