Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 lurxy · Jul 25, 2015 at 11:23 PM · camerarotationparentchildfirst person

First Person Camera not being child of the character/ Set child's rotation to global rotation

Hey there,

I'm relatively new to Unity and I am trying to create a FPS with physics similar to Mario Galaxy where you can hop from planetoid to planetoid and such things. I am now facing a problem with my camera when changing the planet. In my scene, every planetoid has a trigger around them and when a rigidbody touches it, it is attracted by the planetoid. This is true for projectiles as well as the player. Now my problem is, when I am changing the planet as player, the player's gets rotated so that his feet land on the ground first. My camera is a child of the player and when the player gets into a new orbit, the camera's x-rotation stays the same, so the camera is "jumping" from one rotation to another. This really affects the orientation and because of that I want the camera to still look into the same direction when changing the orbit.

I already tried to unchild the camera from the player but then I am not able to make the camera's rotation be the player's rotation.

Has anyone of you a solution for this? I would prefer the camera to stay a child of the player but maybe anyone of you has a better solution for this.

Thanks in advance :)

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 Vice_Versa · Jul 26, 2015 at 04:03 AM 0
Share

you could try unchilding the camera, moving the player, then rechilding

avatar image lurxy · Aug 09, 2015 at 09:27 AM 0
Share

Sorry, i was busy for a while and could not reply to your suggestion. I tried to unchild the camera in game, but the problem with this is, that the "jump" in rotation is only delayed until i rechild the camera. $$anonymous$$aybe i did it wrong, i can't even imagine how i could do it. do you have an example or something like that?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by fsdjfsdkjfsdk · Jul 28, 2015 at 10:36 PM

You could try lerping the cameras rotation to smoothly transition from one rotation to another using the Quaternion.Lerp function. I know this is not the full answer, but it will help with the "jumping" from one rotation to another. Here is a tutorial on lerping, if you are new to unity. The tutorial explains how to do it with position, but its the same basic idea for rotation as well.

https://www.youtube.com/watch?v=cD-mXwSCvWc

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 lurxy · Aug 09, 2015 at 09:31 AM 0
Share

Sorry, i was busy for a while and could not reply. I'm sure i could erase the jumping with the Lerp function but i wanted the jump not to happen in the first place. I'm not completely sure now because i had no time to try different solutions the last couple days but it would be optimal if the camera's rotation can only be manipulated by the player. but the camera should always follow my player object and be on the same position relatively to the player.

avatar image
0

Answer by XDSoftworks · Jan 17, 2017 at 11:57 PM

@lurxy try this. it's untested in this form but should work.

 using UnityEngine;
 using System;
 using System.Collections;
 /*
 --------------------------------------------------------------------------------------------
 this is a bare bones version of my cam rig in my game, it is only the core 
 functions for following and rotation, it is very easy to extend into nearly anything.
 --------------------------------------------------------------------------------------------
 */
 public class camrigsimple : MonoBehaviour {
 public Transform target; // set this or it won't follow anything and will spam your console until you do so
 [SerializeField]
 private float smoothTime = 3; // how fast the camera responds to movement, higher = slower
 [SerializeField]
 private float rotationSmooth = 2; // how fast the camera responds to rotation, higher = slower
 [SerializeField]
 private float distance = 3;
 [SerializeField]
 private float height = 1.3f;
 private Vector3 velocity = Vector3.zero;
 
 void Update(){ // use FixedUpdate if following a rigidbody
 if (target){
 Vector3 targetPosition = target.TransformPoint(new Vector3(0, height, -distance));
 transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime * Time.deltaTime);    
 transform.rotation = Quaternion.Slerp(transform.rotation, target.rotation, rotationSmooth * Time.deltaTime);
 }else {Debug.Log("no target!");}
 }
 }

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Child affecting parent rigidbody? 1 Answer

How do I have a Child tell a Parent to move without the Child itself moving 0 Answers

Need camera to follow player, but not the player's rotation. 13 Answers

Make a simple tree 1 Answer

parent object rotate with child camera 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