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 bybyblue · Feb 27, 2013 at 01:54 AM · rotationfpsaxissmoothsingle

A smooth single-axis rotaion (fps camera)

ok, im still relatively a beginner at c# im slowly working on a game (so far so good).

but right now my issue is i have to floating hands that orbit the players side (by the way this is a first person game), but what im trying to currently do is make it so that when looking to the sides i want the hands to gradually realign themselves, or make them stay in place unless the amount turned is significant enough. but i have no idea where to start.

so far all i have is void LateUpdate()

     {
         transform.position = target.position + new Vector3(0, 0, 0);
         transform.rotation = target.transform.rotation; //this is a placeholder
     }


thx in advance.

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

Answer by robertbu · Feb 27, 2013 at 07:23 AM

Below is a script for your functionality. To make it work, the location of the axis of rotation for the hands must match the axis of the camera. You can do this in one of two ways. You can either author the hands with the center at the correct location, or you can use an empty game object. Place the empty game object at the same position as the camera (*don't make it a child). Then position the hands so they look the way you want with respect to the camera view. Finally make the hands a child of the empty game object. If you use the second method, the script goes on the empty game object, not on the hands:

 public class HandRotator : MonoBehaviour {
     private Vector3 v3Offset;
     private GameObject goFollow;
     private float speed = 0.5f;
 
     void Start () {
         goFollow = Camera.main.gameObject;
         v3Offset = transform.position - goFollow.transform.position;
     }
     
     void Update () {
         transform.position = goFollow.transform.position + v3Offset;
         transform.rotation  = Quaternion.Slerp (transform.rotation, goFollow.transform.rotation, speed * Time.deltaTime);
     }
 }
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 angrycarrots · Feb 28, 2013 at 12:04 AM 0
Share

hey thanks for directing me here, but i dont understand what you mean when you say that the rotation must match a camera?

avatar image robertbu · Feb 28, 2013 at 12:21 AM 0
Share

If you place the hands (or light) in the exact same place as the camera (i.e. their positions as viewed in the inspector are identical) do the hands (or light) look the way you want them to look? In the case of the light it will more be about how the light plays in the scene. If the answer is yes, then the camera and the hands/light will share the same origin and you can attach the script to the hands/light. If the answer is no, then you have to do the "trick" I outline with the empty game object. The object that is pivoting must placed at the same position as the camera in the editor. If the hands/light need to be some place else, you can make the a child of the object that is at the correct position. Actually in the case of a light since it doesn't have a physical object near the camera, you might be able to get away with some offset.

avatar image bybyblue · Mar 03, 2013 at 04:10 PM 0
Share

ok well for those who dont understand my delima i made a diagram alt text

pretty much when you view goes to the left for example,you catch a glimpse of your hand dependent on how fast you turn. this is probably the best i can explain it. and im going to try robertbu's answers later today when i get the chance.

example.png (2.9 kB)
avatar image robertbu · Mar 03, 2013 at 04:28 PM 0
Share

As long as you setup the rotation point of the hands to match the origin of your object, the above code should work for allowing the use to "catch a glimpse of your hand."

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

10 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

Related Questions

How to rotate the axis of a 3D GameObject 1 Answer

How to state synchronize the rotation of one axis? 1 Answer

FPS Run Animation Problem with Rotation 0 Answers

different axis for different objects? 1 Answer

Rotating wrong 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