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 Satoronus · Oct 30, 2018 at 10:59 PM · cameramovementthird-person

How to make my player walk according to the cameras direction?

I build a third person game with an orbital camera. The player is moving on a Z/X plane. I want the player to walk forward (or any direction) according to the camerasview(Rotation) but only on the Z/X plane on which the player walks on. The Camera should work as a way to explore the environment by orbiting around the player and not moving anything by doing so. Haven't found any soulution yet that fit my game. PlayerController Class:

   //Moving
         transform.Translate(Input.GetAxis("Horizontal") * Time.deltaTime * Playerspeed, 0f, Input.GetAxis("Vertical") * Time.deltaTime * Playerspeed, Space.World);

Camera Controller Class:

 {
     public Transform target;
 
     public Vector3 offset;
     public float zoomSpeed = 4f;
     public float minZoom = 5f;
     public float maxZoom = 15f;
 
     public float pitch = 2f;
 
     public float yawSpeed = 100f;
 
     private float currentZoom = 10f;
     private float currentYaw = 0f;
 
     void Update()
     {
         currentZoom -= Input.GetAxis("Mouse ScrollWheel") * zoomSpeed;
         currentZoom = Mathf.Clamp(currentZoom, minZoom, maxZoom);
 
         currentYaw -= Input.GetAxis("Mouse X") * yawSpeed * Time.deltaTime;
     }
 
     void LateUpdate()
     {
         transform.position = target.position - offset * currentZoom;
         transform.LookAt(target.position + Vector3.up * pitch);
 
         transform.RotateAround(target.position, Vector3.up, -currentYaw);
     }
 
 }




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 Satoronus · Oct 30, 2018 at 11:05 PM 0
Share

alt text

test.png (171.8 kB)

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by SunnyChow · Oct 31, 2018 at 04:22 AM

 Vector3 forward = Camera.main.transform.forward;
 forward.y = 0;
 forward.Normalize();
 Vector3 right= Camera.main.transform.right;
 right.y = 0;
 right.Normalize();
 transform.position += Input.GetAxis("Horizontal") * Time.deltaTime * Playerspeed*right + Input.GetAxis("Vertical") * Time.deltaTime * Playerspeed*forward;
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 Satoronus · Oct 31, 2018 at 11:52 AM 0
Share

That works fine but now I have a problem with the Playercharacter alignment (because it still depends on the players local movement and not the cameras or the global movement ect.)

 //Alignment-Rotation 
 float moveHorizontal = Input.GetAxisRaw("Horizontal");
 float moveVertical = Input.GetAxisRaw("Vertical");
 
 Vector3 movement = new Vector3(moveHorizontal , 0f, moveVertical);
 
 if (moveHorizontal != 0 || moveVertical != 0) //align only when moving
 {
     transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(movement), 0.20F); //smooths the rotation-alignment and makes the player face the...
 }


avatar image
0

Answer by zozo36769 · Nov 03, 2018 at 07:16 PM

even though my computer is broken so I can't mess around with coding, I'm still watching it because I love this. Whatsapp Messenger Hotstar

Comment
Add comment · 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

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

195 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

Related Questions

Third Person Camera Help? 0 Answers

Movement with Camera 2 Answers

Rigidbody Moveposition not working when Camera follows object? 0 Answers

Camera Relative Movement 2 Answers

First person camera restriction. 1 Answer


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