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 /
avatar image
0
Question by hanaharu7 · Feb 04, 2014 at 03:13 AM · cameralookatcamera-looktransform.

camera Lookat FPC problem

Im trying to modify this deathscript so that the camera stops and then looks at the player as they move. I've come as far as getting the Main camera to unparent itself from the FPC, but I can't seem to get it to stay on the player. At the moment all it does is reset its position.

 var target : GameObject; // drag here the end empty object


 function KillCam(){
 var cam: Transform = Camera.main.transform; // get camera transform
 cam.parent = null; // detach camera from the player
 
 cam.LookAt(target.transform.position); // make it look at the player
 
 yield; 
 }

Any help would be greatly appreciated

Comment
Add comment · Show 2
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 Nanobrain · Feb 04, 2014 at 04:48 AM 0
Share

Why are you un-parenting the camera? Shouldn't need to do so. Just use lookAt.

avatar image hanaharu7 · Feb 04, 2014 at 06:02 AM 0
Share

Well want the camera to stop moving with the player and simply look at them. if I don't unparent it will stay with the player(in first person)

the effect I'm going for is sort of like going from first person to third. so the player will fall ahead of the camera.

Although, even without it I still can't seem to get it working

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by RyanZimmerman87 · Feb 06, 2014 at 08:37 AM

I would probably just set up all your camera logic into two sections one for being alive and one for being dead.

For Example:

 //this script is on Camera
 
 Transform cameraTransform;
 
 Transform playerTransform;
 
 //speed for camera
 float cameraMoveSpeed;
 
 void Start()
 {
 cameraTransform = transform;
 playerTransform = GameObject.Find("Player").transform;
 
 cameraMoveSpeed = 1;
 }
 
 void LateUpdate()
 {
 //easy dead or alive bool access for sake of example
 
 if (PlayerScript.playerAliveBool == true)
 {
 //all normal camera behavior
 }
 
 else if (PlayerScript.playerAliveBool == false)
 {
 //dead camera behavior
 cameraTransform.LookAt(playerTransform.position);
 
 //move backwards at cameraMoveSpeed
 cameraTransform.position += -camerTransform.forward * cameraMoveSpeed * Time.deltaTime;
 
 
 //move up at cameraMoveSpeed
 cameraTransform.position += camerTransform.up * cameraMoveSpeed * Time.deltaTime;
 
 }
 
 }


That should move the camera simply upwards and back from the player. If you want something nicer you might want to just create two Transform variable when you die and use lerp to move between the two (one for spot of camera right at death, one at a spot relative to the death spot).

For example:

 cameraTransform.position = Vector3.Lerp (deathStartTransform.position, deathEndTransform.position, .1f);


You could also just use vector positions to move around rather than transform.forward or transform.up stuff.

Example:

 cameraTransform.position = new Vector3 (cameraTransform.position.x, cameraTransform.position.y +.1f, cameraTransform.position.z - .2f);
 

I really have no idea how any of this would look so you would need to adjust variables this is basically just syntax examples.

There's really a million different ways to do this type of thing so you just need to find what looks best to you.

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 hanaharu7 · Feb 06, 2014 at 07:06 PM 1
Share

This helped immensely! I was able to get a good result by using the edited script with your move camera backwards. Plus I got a little practice converting c# to javascript. $$anonymous$$any Thanks!!

avatar image
0

Answer by Nanobrain · Feb 04, 2014 at 06:41 AM

Don't un-parent the camera. Instead, I would suggest just moving the camera along it's local axises away from the player along with lookAt.

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 hanaharu7 · Feb 06, 2014 at 08:06 AM 0
Share

I'm trying to go with what you said but I'm not sure what I'm doing wrong. I looked around and made this script that does get the cam to look at whatever I choose, but it wont move the cam at all after I tried to add the translate part.

 var target : Transform;
 var speed = 2.0;
 var smooth = 5;
 
 cam =  Camera.main;
 
 
 function Awake(){
  var script3 = GetComponent("DeathScript"); 
  script3.enabled = false;
 }
 
 function LateUpdate(){
     var cam1 = Camera.main.transform;
     cam1.Translate(Vector3.-forward); 
     var quaterion= Quaternion.LookRotation(target.position - cam1.position);
     transform.rotation = Quaternion.Slerp(transform.rotation, quaterion, speed * 0.02);
 
 }
 

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

Quaternion.LookRotation is making my object rotate around a point? 1 Answer

third person camera 2 Answers

Change the object the camera looks at? 1 Answer

Make the terrain ignore Raycast if in between Camera and Player? 1 Answer

Change 3D Camera to 2D 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