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 fagtr0n · May 05, 2014 at 09:47 PM · camerarotationslerpinput.getaxis

Slerp camera rotation moves on it's own at runtime?

I have a script to rotate the camera with an input axis, it works mostly. The big problem is that it starts moving on run time without input, and when I use the input, it eventually resists going further, and drifts back to centre. Trying to figure out how to stop this, so the input axis just rotates the camera normally without restriction, but does nothing when no input is used...? I am beginner to C#, but am trying my hardest to learn.

there is a rigid body attached to the camera, set to no gravity, no drags, and mass of 1.

the axis inputs are set to gravity and sensitivity 3, and dead at 0.005.

the camera has one child, which is a light.

Any input is appreciated! Danke! ; D

 using UnityEngine;
 using System.Collections;
 
 public class control_rotator : MonoBehaviour {
 
 
     //rotate variables
 
     public float horizontalSpeed = 0.3F;
     public float verticalSpeed = 0.3F;
 
     public float speed = 0.3f;
     public Transform target; // set to the main camera (itself)
 
     //movement variables
 
     public float moveSpeed = 3.0f;
 
     void Update() {
 
 
         // input and transform rotation values
 
         float h = horizontalSpeed * Input.GetAxis("Horizontal2");
         float v = verticalSpeed * Input.GetAxis("Vertical2");
         transform.Rotate(-v, -h, 0);
 
 
         //locate and slerp rotation values
 
         Vector3 relativePos = target.position - transform.position;
         Quaternion where = Quaternion.LookRotation(relativePos);
 
         transform.rotation = Quaternion.Slerp(transform.rotation, where, Time.deltaTime * speed);
 
         // input and transform movement values
 
         float moveHorizontal = moveSpeed * Input.GetAxis ("Horizontal");
         float moveVertical = moveSpeed * Input.GetAxis ("Vertical");
 
         //movement vectors and physics
         
         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
     
         rigidbody.velocity = movement * moveSpeed;
 
 
 
 
 
 }
 }
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
Best Answer

Answer by robertbu · May 06, 2014 at 07:45 AM

Lines 29 - 34 are causing the object to try and look at the 'target'. Line 26 is trying to rotate based on user input. So you have two different kinds of rotation code fighting with each other. I'm not sure of your game needs, but deleting lines 29 - 34 will allow the user input to rotate the object without restriction.

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 fagtr0n · May 07, 2014 at 12:19 AM 0
Share

thanks, that works! it also works with the target set to nothing. i think i got confused how slerp works, and it seems to still interpolate somehow?

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

20 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 avatar image avatar image avatar image avatar image

Related Questions

Transition current camera rotation to 0,0,0 1 Answer

Rotation always changing values! 1 Answer

Rotate Camera in Increments with Damping 2 Answers

Problem with wave like movement when rotating around X and Y axis with mouse input // Please Close/Delete 1 Answer

Gameobject Rotation Calculation 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