Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by IKilledKenny_2 · May 26, 2015 at 06:49 PM · camerajavascriptcollisioncamera-look

Camera Follow

Hello Unity3D i have a question about camera following.How can i make my character camera follow on the opponent except for the x-axis?For example when my characters camera follow the opponent flying into the air but it lose some of the visual view of my character.I want to camera to follow but not on the x axis.IF anyone knows how i can do this?Can you please tell me how?

P.S Heres what i got so far

 var target : Transform;
 var rotationSpeed = 5;
 var myTransform : Transform;
 
  
 function Awake() {
         myTransform = transform;
 }
  
 function Start() {
 
 
     if (GetComponent.<Rigidbody>())
         GetComponent.<Rigidbody>().freezeRotation = true;
  
         target = GameObject.FindWithTag("Dummy").transform;
             // Make the rigid body not change rotation
 }
 
  
  
 function LateUpdate () {
    
 
     myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
     Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
 }
 
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 Xarbrough · Jun 14, 2015 at 11:18 PM

 float damping = 3f;
 
 void LateUpdate()
 {
     // if target is not null
     if (target) 
     {
         //Set targetPosition y and z, but keep the x value at the current position
         targetPosition = new Vector3 (transform.position.x, target.position.y, target.position.z);
         
         transform.position = Vector3.SmoothDamp (transform.position, targetPosition, ref velocity, damping);
     }
 }


Try this. Just define a target position, which has the same x component as your current position. Then either Lerp (or SmoothDamp, which is similar) towards the target position, or do target.position - transform.position to get the vector in which you want to move. Then you could translate or addforce in the direction. Depends on how your movement should work.

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 IKilledKenny_2 · Jun 14, 2015 at 11:28 PM 0
Share

what im trying to do is that i want the camera or player to not move on the x axis whenever i jump or send the opponent flying

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

20 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

Related Questions

A little help with this camera script please? 3 Answers

OnTriggerEnter not working for NavMesh 1 Answer

My Scene View is Fine but my Game View is just black but the Camera Works 0 Answers

Player camera targeting/locking another object 0 Answers

Main Camera Stops working or just freezes? 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