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 LimboWorld · Jun 26, 2014 at 11:42 AM · cameratransformobjectorbit

Camera Orbiting Character: How to make an object move with another with no rotation

Hello. I am faced with a problem I need to tackle in my android game. I am reasonably new to scripting, and I will do my best to explain this problem.

I'm working on a camera that is supposed to orbit a third person character with touch swipe (it will be built on android). It is a 3d adventure game, third person character with joysticks for movement and touch swipe for camera rotation.

I need the main camera to be orbiting a character. My character is going to be rotating alot, so I need the camera to not rotate with the character.

-----What I've done now is:

1) I've created an empty object called "CameraPivot1" to my main character positioned at the neck.

2) I've created another empty object called "CameraPivot2", which has the main camera as a child to this. [CameraPivot2 is NOT a child to CameraPivot1].

3) I have a script that will rotate the 'CameraPivot2' and thus the camera AROUND this point.

What I need is a script that will position CameraPivot2 exactly where CameraPivot1 is. My character will be moving+rotating left + right, and it is important to keep the position of CameraPivot2 onto CameraPivot1. How does the c# script go? all I know is that is that it must be in the void update() because I need to update the position of CameraPivot2 onto CameraPivot1 every frame.

-----Why am I doing this? I've tried parenting the two together and using quaternion rotation script in CameraPivot2 to cancel the rotation of the camera from its parent, but this has ended up with jittery camera movement whenever I rotate the character AND camera at the same time.

SO... if I keep CameraPivot 1 and 2 NOT parented with each other, but held together, when I rotate the character, it will rotate CameraPivot1, but NOT CameraPivot2, and since the main camera is a child to CameraPivot2, it will not rotate the camera etc... more stable and no jitter. How does the C# script go?

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
Wiki

Answer by shaneK001 · Jun 26, 2014 at 02:15 PM

I'm not sure what you're trying to do exactly, perhaps an image would work better? Anyways, If you have a target object somewhere on scene. It doesn't need the same position as camera, it's just for the target rotation.

Then, use something like this script: http://docs.unity3d.com/ScriptReference/Quaternion.RotateTowards.html

Attach that to the camera you want to have independent rotation, drag your target rotation object on in the inspector, and then rotate that target object another way to control your camera. That's what I think you're trying to do anyways.

Comment
Add comment · Show 2 · 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 LimboWorld · Jun 27, 2014 at 08:48 AM 0
Share

Thanks for your answer shane$$anonymous$$001, but that is not exactly what I am looking for. This picture should hopefully explain.

The point of doing this is to have the camera orbit rotation to be independant to the main character, but at the same time, move WITH the character. (When I swipe, it is CameraPivot2 that rotates, which makes the camera orbit this).

I'm looking for a simple script that would make one object and another object "stick" together.

In this case, I'm looking for a script that can make CameraPivot2 "stick" with CameraPivot1 at all times WITHOUT parenting them together.

(I've parented them together before but what happens is whenever the character rotates, the camera spins out of control. I've tried quaternion rotate to cancel this inherited rotation, but that has just left me with jittery camera rotation).

alt text

untitled.png (472.1 kB)
avatar image shaneK001 · Jun 27, 2014 at 09:20 AM 0
Share

Just the position? make this a c# script (everything between // and //) called $$anonymous$$atchTargetPosition and put it on the camerapivot2 object as a component. Do not make it a child or a parent of the other objects. You must drag the target on in the inspector

//

 using UnityEngine;
 using System.Collections;
 
 public class $$anonymous$$atchTargetPosition : $$anonymous$$onoBehaviour {
 
     public Transform target;
 
     void Update() {
         
         transform.position = new Vector3(target.position.x,target.position.y,target.position.z);
     }
 }

//

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How do I move the camera to another object in the scene on mouse down? 1 Answer

Script not function if mouse is on object 1 Answer

Push object in direction of camera 0 Answers

Rotating camera around object up/down problem 0 Answers

How to get the constant Y rotation of the camera 2 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