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 dragonking300 · Dec 17, 2016 at 08:45 PM · c#scripting beginner

How do I make my camera follow the player while also following its rotation?

My camera is able to rotate relative to the player's position but it was stay in that rotated position and not move until I press the button to make it move.. How do I make my camera be dynamic by rotating to face the player from all 4 directions while also be dynamic by following the player's movements.

Edit: I've tried using offset scripts but it doesn't and just cuases my camera to do 360s while staying behind my player

my camera script for calculating the math

 using UnityEngine;
 using System.Collections;
 
 public class CameraControll : MonoBehaviour
 {
     public Transform target;
 
     public float horizMove = 45f;
     public float VertMode = 15f;       
 
     public void MoveHorizontal(bool left)
     {
         float dir = 1;
         if (!left)
             dir *= -1;
         transform.RotateAround(target.position, Vector3.up, horizMove * dir);
 
     }
 
     public void MoveVertical(bool right)
     {       
         float dir = 1;
         if (!right)
             dir *= -1;
         transform.RotateAround(target.position, transform.TransformDirection(Vector3.right), VertMode * dir);
    }  
 }

my script for the inputs

 using UnityEngine;
 using System.Collections;
 
 public class InputManager : MonoBehaviour
 {
 
 
     CameraControll cam;
 
     void Start()
     {
         cam = GetComponent<CameraControll>();
     }
 
     // Update is called once per frame
     void Update()
     {
         if (Input.GetKeyDown(KeyCode.LeftArrow))
         {
             cam.MoveHorizontal(true);
         }
         else if(Input.GetKeyDown(KeyCode.RightArrow))
         {
             cam.MoveHorizontal(false);
         }
         else if (Input.GetKeyDown(KeyCode.UpArrow))
         {
             cam.MoveVertical(true);
         }
         else if (Input.GetKeyDown(KeyCode.UpArrow))
         {
             cam.MoveVertical(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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ProtoTerminator · Dec 18, 2016 at 04:07 PM

If you want it to always follow your player perfectly, simply set the player as the camera's parent (drag and drop it in the hierarchy). That way you never have to change its position, only its rotation (with RotateAround. If you want a delay-follow, set up a dummy transform like you would the camera previously, and then every frame have the camera lerp its position and rotation to the dummy object Vector3.Lerp(camera.transform.position, dummy.transform.position, 0.5f)

Comment
Add comment · Show 6 · 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 dragonking300 · Dec 20, 2016 at 01:04 AM 0
Share

well the problem is when I make my camera child of my sphere the camera rotates like crazy and when I use the typical offset( offset = transform.position - player.transform.position lateupdate() transform.position = player.transform.position + offset;) the camera just flies into the air

avatar image dragonking300 dragonking300 · Dec 20, 2016 at 11:23 PM 0
Share

bumberoooo

avatar image ProtoTerminator dragonking300 · Dec 21, 2016 at 05:39 AM 0
Share

Are you using local or global positions and rotations?

avatar image dragonking300 ProtoTerminator · Dec 21, 2016 at 02:26 PM 0
Share

whats the difference between local and global positions .-. ? I'm new so please elaborate

Show more comments
avatar image dragonking300 · Dec 21, 2016 at 02:46 PM 0
Share

ok thx rett

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

259 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

how to apply force on correct direction in wall jump using Rigidbody 2 Answers

how do i add a offset to my sword rotation? 2 Answers

Enabling multiple Monobehaviour Components in a game object 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