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 Flisijn · Mar 24, 2013 at 08:11 PM · camerarotationsmoothrunningdegrees

Turning the camera down smoothly while running

How can I turn the camera down smoothly for xx degrees while running and returns to his original state while walking?

I only need the script for moving the camera down and up, can someone give me an example?

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

2 Replies

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

Answer by gribbly · Mar 24, 2013 at 09:23 PM

A very easy way to do this:

  1. Create an empty game object called "LookTarget" as a child of your character

  2. In your camera script, have the camera look at LookTarget every frame:

    Transform lookTarget = GameObject.Find("LookTarget").transform; //put this in Start()

    transform.LookAt(lookTarget); //put this in Update()

  3. In your character script, move LoookTarget according to character state... you can do simple vertical moves on the Y axis and the camera will automatically track.

This method has the advantage of letting you get the behavior you want without dealing with rotations directly, which can be complex.

As an optimization, you may want to assign lookTarget in the inspector instead of using GameObject.Find.

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 Flisijn · Mar 24, 2013 at 10:39 PM 0
Share

Can you give me an example of step 3? I don't know how to do this in code..

avatar image gribbly · Mar 24, 2013 at 11:21 PM 0
Share

Sure, so assu$$anonymous$$g you have a "LookTarget" object that is a child of your character object, you can do this in your character script.

First set up a variable so your character script can talk to LookTarget:

 public var lookTarget:Transform;

...that wlll show up in the inspector when you select your character. Drag the LookTarget object onto it to assign it.

Now in your update function you can talk to the LookTarget object via the var lookTarget.

 function Update(){
   if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Alpha1)){
     lookTarget.Translate(0.0f, 1.0f, 0.0f);
   }
   if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Alpha2)){
     lookTarget.Translate(0.0.f, -1.0f, 0.0f);
   }
 }

Now when you run the game you can press 1 to move LookTarget up, 2 to move it down.

When you have it working this way, you'll want to replace the Input.Get$$anonymous$$eyDown events with something relevant to your game - you wanted to link it to character state, you'll have to work out the details, but as long as you can do something like "if this state then..." it should work fine.

avatar image
0

Answer by Josh707 · Mar 24, 2013 at 11:23 PM

You can do it with animations which work well as they interpolate if the timescale is lowered. Add an empty gameobject between the camera and the player and animate it rotating down slightly and then back to 0,0,0 rotation. You'll be able to control it normally but it will also be pulled down. This is what I did for left and right footsteps, it looks nice and this sample code should give you an idea.

 if(moving == true){
     if(left == true){
         if(!anim.isPlaying){
         anim.Play("walkLeft");
         right = true;
         left = false;
         }
     }
     if(right == true){
         if(!anim.isPlaying){
         anim.Play("walkRight");    
         left = true;
         right = false;
         }
     }
 }

If you just want it going up and down, in Update() just do something like this:

 if(moving == true){
     if(!anim.IsPlaying){
         anim.Play("lowerCamera");
     }
 }
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 gribbly · Mar 24, 2013 at 11:30 PM 0
Share

This is also a good approach!

avatar image Flisijn · Mar 26, 2013 at 08:26 AM 0
Share

When I use this approach my camera is freezed at certain rotations, I can only rotate up and down and sometimes with a wierd rotation to other points.

I've added the script to the empty GameObject, which is a child of the Player and the parent of the main camera.

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

12 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

Related Questions

Smooth Attached Object movement 1 Answer

How Can I Smooth This Camera Code 0 Answers

Camera, Look rotation, smoothly? 0 Answers

smoothly rotate camera around an object with momentum 0 Answers

Smooth Rotation 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