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 infinitypbr · Jun 18, 2013 at 04:20 AM · cameraslerptop down

Slerping Camera Top-Down view, how to keep it over player?

Here's a video of the issue -- as the player walks forward, the camera starts to lag behind the player due to the slerp I'm using, and camera starts showing less of a top-down view and more 3rd person. I'd like to change this so that the camera stays more overhead.

http://www.sfbaystudios.com/slerpissue.mov

However, I use the slerp in the code to keep the camera from moving left/right just a bit with every step the player takes. It uses Mechanim Root Motion for the walking, so every step the player officially is moving forward but kind of goes a bit left and a bit right. I use the slerp to smooth out the motion and keep the camera from wobbling.

Any idea how I can change this?

 using UnityEngine;
 using System.Collections;
 
 public class AttachCamera : MonoBehaviour
 {
     Transform myTransform;
     public Transform target;
     public Vector3 offset = new Vector3(0, 5, -5);
     
     void Start()
     {
         myTransform = this.transform;
     }
     
     void Update()
     {
         myTransform.position = Vector3.Slerp(myTransform.position, target.position + target.TransformDirection(offset), (Time.deltaTime / 2));
         myTransform.LookAt(target);
     }
 }
Comment
Add comment · Show 8
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 robertbu · Jun 18, 2013 at 04:42 AM 0
Share

Nice atmosphere in your game. First, I don't think you need Slerp() here. It seems more like a Lerp() situation. Have you tried increasing the speed of the Slerp()? Typically the last parameter of the Slerp/Lerp is written as '`Time.deltaTime * speed`'. In your case by dividing by 2, your speed is 0.5. Try replacing the last parameter and play with different speed values.

avatar image infinitypbr · Jun 18, 2013 at 04:55 AM 1
Share

THanks -- the graphics deserve a HUGE shout out to $$anonymous$$ichael O (search "Top Down $$anonymous$$obile" in the asset store). All of his work is A$$anonymous$$AZING, and this is one of them, the layout etc is actually his demo scene.

However, increasing the speed keeps the wobble in the camera. Time.deltaTime keeps the wobble just a bit visible, so anything faster would be worse. But even then, the camera still moves too far to be real "top-down" anymore.

How do you think a lerp would work better?

avatar image robertbu · Jun 18, 2013 at 05:23 AM 0
Share

The 'S' in Slerp stands for 'spherical', and I just don't see any spherical movement here.

avatar image infinitypbr · Jun 18, 2013 at 05:33 AM 0
Share

I thought about doing an "Average" thing, but figured there had to be a simpler way. I thought about trying to lerp only the y axis on the myTransform.position, but couldn't figure out how to do it correctly.

avatar image robertbu · Jun 18, 2013 at 05:42 AM 0
Share

This is one of those things that, unless you've faced it before, you will just have to play with some concepts. I'd work with trying to average the left/right movement as a next step.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by whebert · Jun 18, 2013 at 06:15 PM

I haven't fully tested this, but something like this may work in your situation, tweaked of course. If you had a smooth follower, not a camera but an empty game object, that followed your character (target) around with sort of a low-pass filter for position and rotation, then had your camera follow the smooth follower like you are following the character now, but without the Lerp/Slerp you are using on the camera, just straight up follow. The following scirpt may work as the low-pass filtered smooth follower - I am using the Lerp and Slerp as usual, but they shouldn't react much to very small changes, and would progressively react more for larger changes, clamped on both ends.

 using UnityEngine;
 using System.Collections;
 
 public class SmoothFollower : MonoBehaviour {
     
     public Transform target;
     
     
     // Use this for initialization
     void Start () {
         
         transform.position = target.position;
         transform.rotation = target.rotation;
     
     }
     
     // Update is called once per frame
     void Update () {
         
         transform.position = Vector3.Lerp(transform.position, target.position, Time.deltaTime * Mathf.Clamp((target.position - transform.position).sqrMagnitude * 8, .1f, 5));
         transform.rotation = Quaternion.Slerp(transform.rotation, target.rotation, Time.deltaTime * Mathf.Clamp(Vector3.Angle(target.forward, transform.forward)/90 * 4, .1f, 5));
         
     }
 }
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 infinitypbr · Jun 19, 2013 at 04:36 AM 0
Share

That may work -- I did not test it.

Ins$$anonymous$$d, I found an animation that didn't itself have the wobble, or something, because I got it working. Not 100% sure what. I did read something about how baking the rotation when yo uset up the animation may fix it.

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

16 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

Related Questions

How to know when camera stops rotating using lookRotation 0 Answers

Top down shooter camera follow cursor 2 Answers

How do I translate around a circle? 3 Answers

Quaternion Slerp Sanity Check 1 Answer

How to prevent continuous spinning while aiming at the screen's center? 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