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
1
Question by bitbyte · Feb 16, 2012 at 05:35 AM · rotationmousespaceslerpmouse control

Slerp/Rotational Problem Query

First, I am trying to design a simple space-sim, which doesn't seem to be so simple in fact. Second, let me show you a picture.

alt text

Fig(A): It is a my gameplay view. Fig(B): Scene view with World/Local positioning of my gameobject. Fig(C): Let's skip this for now as I will explain it in due time. Chart: A Hierarchy chart where 4 gameobjects are child of one single gameobject.

Now, onto my problem:

I have this code:

 public class mouseTurn : MonoBehaviour {
     public float speedmultiplier = 0.005f;
 
     void FixedUpdate(){
        float xvalue = Input.mousePosition.x;
        int screenwidth = Screen.width;
        float xmidpoint = screenwidth/2;

        constantForce.relativeTorque = new Vector3(0f,(xvalue-xmidpoint)*speedmultiplier,0f);
     }
 }



This script is attached to my "Main GameObject"(which also has a RigidBody/ConstantForce attached to it), which enables the entire hierarchy to rotate, which is working absolutely fine[I ommited a lot of code(ex. Y-Axis rotation) and other things to make my question precise and onto point].

What I want to accomplish is that when ever I rotate my object, the child object "Capsule" should rotate just a small amount, to the right/left of my camera, in Time t as to show the effect of capsule turn(For relevance: check Freelancer/Black Prophecy gameplay)[As shown in Fig(C)].

I tried using Quaternion Slerp but could not figure out a way to achieve said goal. While using quaternion slerp, my "Capsule" would not rotate along with camera.

If you see my previous post, you can see that I was able to achieve a fluid rotation using "ConstantForce", which you can also see in the give code. Since, I have optimized the said code a lot(i.e why I have only posted a snippet of it).

So if any Unity Gurus are out there who can help me with my dilemma, I would be very thankful(Atleast show me a path to a solution).

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 syclamoth · Feb 16, 2012 at 05:53 AM

Basically, instead of making the camera a direct child of the main movement manager, make it seperate with a script that goes something like this-

 public Transform followThis; // Put your capsule here
 public float smoothingFactor = 3; // Make this higher to make the camera stick more closely to the target. 

 private Vector3 posOffset;
 
 void Start()
 {
     posOffset = transform.position - followThis.position;
 }
 
 void LateUpdate()
 {
     transform.position = followThis.position + posOffset;
     transform.rotation = Quaternion.Slerp(transform.rotation, followThis.rotation, Time.deltaTime * smoothingFactor);
 }

You may, in fact, wish to put this script on a 'parent' object, that sits on top of the capsule itself, with the actual camera a child of that object offset a fair way.

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 bitbyte · Feb 16, 2012 at 06:57 AM 0
Share

Thank you for the code snippet. I tried this code in every other way I could think of, but the results were not what I was trying to go for. Pardon my rudeness but let me clarify a bit more.

What I was going for: The camera to follow "Capsule/$$anonymous$$ain Gameobject"'s throughout their rotation, with, capsule rotating a bit to the left/right(depending on the axis of rotation), which exposes capsule's left/right side a bit to the camera, and stay there throughout the rotation in said axis(and this should happen like a form of small animation where capsule seems to rotate a bit to the left/right of the camera view that is why I brought up slerp in above post, because I thought that is how one could achieve said task).

What above code did for me: The camera rotates independently of "$$anonymous$$ain Gameobject/Capsule", which makes capsule invisible after a certain degree of rotation(even with passing of "$$anonymous$$ain Gameobjects/Capsule"'s Transform, and, does not matter whether "Camera" is a child or independent of "$$anonymous$$ain GameObject/Capsule").

I will tinker some more with the code above.

P.S. A/B means Either/Or in my comment.

avatar image syclamoth · Feb 18, 2012 at 02:55 AM 0
Share

$$anonymous$$ake the camera a child of a 'pivot' object, which occupies the same space as the capsule. Put the interpolation script on the pivot, not on the camera itself.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rotation always changing values! 1 Answer

Slerp doesnt go to the rotation its supposed to go to 1 Answer

How to rotate an object by its pivot in script 3 Answers

click to move workig script!! but pls help with rotation!! :( 1 Answer

Use Lerp to rotate object 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