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 McMutton · Sep 18, 2011 at 08:19 PM · camerarotationcontrol

Help with camera coding - Modern Zelda-style camera

Ladies, gentlemen.

Currently, I'm attempting to set up a camera system akin to the modern Zelda titles, wherein the camera stays a certain distance from the player, and will rotate to look at them if they move to either side, but not if they move either away from or towards it.

The basic Smooth Follow camera does the side rotations moderately well, but the issue I keep having is that when the player moves toward the camera, it freaks out and rotates around the player incredibly fast rather than just staying put and moving with them.

Any insight?

~~EDIT~~

So I tried adding a bit that would only have the Smooth Follow's rotation bits take effect if the player's rotation isn't between 5 more than and five less than the camera's rotation (Facing the camera), or between 175 and 185 more than the camera's rotation (Facing away):

     if(ActivePlayer.rotation.y >= transform.rotation.y + 5 && ActivePlayer.rotation.y <= transform.rotation.y - 5
     || ActivePlayer.rotation.y >= transform.rotation.y + 185 && ActivePlayer.rotation.y <= transform.rotation.y + 175){
         //Do rotate
     }
     else
         //Don't rotate


Sadly, this didn't work for some reason. Was there a misstep in my logic or something?

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
1
Best Answer

Answer by testure · Sep 18, 2011 at 09:38 PM

I have a similar camera setup in my game- and I've solved this by writing my own camera handler from scratch. Based on my experience as a 3D artist, I've actually built the camera in a way that a 3D modeling application would build it- Using a root, a camera, and a target.

The heirarchy looks something like this:

 Camera root
 --> Camera
 --> Target

The root is used for moving and rotating the camera, and the camera itself is only set at the optimal height and distance away from the root. The camera always looks at the target- this makes it easy to smoothly look at different things, rather than transform.LookAt snapping to a new transform.

So in my game, I simply match the root's position to the player's position, and as the player moves around the camera will always be at the designated distance and height.

There's other logic that handles smooth transitions, orbiting around the player, and occlusion culling of course, but that's beyond the scope of this question.. and a very long topic in itself.

Hopefully this helps a bit. The key thing with my setup is that I don't really move the camera at all (unless the player has changed the height or distance of the camera)- I move the root.

Comment
Add comment · Show 4 · 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 McMutton · Sep 22, 2011 at 09:42 PM 0
Share

So, this Root... Is it parented to the target, or is there a script attached that makes it copy the target's position?

avatar image testure · Sep 22, 2011 at 09:46 PM 0
Share

No, the root is the root of the heirarchy. the children of root automatically follow root because they are parented to it.

avatar image McMutton · Sep 26, 2011 at 06:41 PM 0
Share

Ah, okay. Either way, I was able to make a suitable setup derived from your method. Thank'eh!

avatar image McMutton · Oct 03, 2011 at 09:03 PM 0
Share

Say, have you ever experienced issues with the camera randomly warping about, regardless of where the parent node is?

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 to make camera position relative to a specific target. 1 Answer

Very weird rotation axis bug 1 Answer

Why the control with gyroscope inverted when I make 180 degrees turn? 1 Answer

Keyboard Controlled Overhead Camera Rotation 0 Answers

MouseOrbit script in alternate space 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