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 TheShadyColombian · Jan 20, 2015 at 09:43 PM · c#rotationscript.parabola

Set Object X-Rotation to Its Vertical Speed (with a 360º Limit)

Hello! My name is Juan and there's something I need to put in my game. I want my GameObject to stay parallel/(whatever the name is for 90º intersection, I forget.) to the parabola of movement when jumping. Kinda like this; ![alt text][1]

My character is that cat-like thing and the parabola is, well, the parabola of height/distance (neither are accurate).

Thanks in advance to whoever helps!

demo.png (29.3 kB)
demo.png (29.3 kB)
Comment
Add comment · Show 3
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 TheShadyColombian · Jan 20, 2015 at 09:44 PM 0
Share

I had to re-type this because I thought I closed it and then I posted it and turns out it was open in another tab XD

avatar image skylem · Jan 21, 2015 at 12:32 AM 0
Share

there is a few options to setting an objects rotation/position You could use a Vector3.Lerp or directly set the eulerAngles, if your object has rigidbody, there is also AddRelativeTorque and Force, if you'd like examples for any of these let me know and ill write some.

avatar image TheShadyColombian · Jan 21, 2015 at 01:07 AM 0
Share

vector3.lerp sounds fancy so let's go with that :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by skylem · Jan 21, 2015 at 04:55 AM

this is an example of a Lerp, one for the position another for rotation via quaternion. the end position and rotation will be copied from the transform assigned to target. hope this helps you sorry for the delay.

 public Transform target;
     void Start () {
     
     }
     // Moving the object this script is on from Position A, to Position B, the last value is the frames it does this over.
 // lerp can also be used with quaternion values.
     void Update () {
         transform.position = Vector3.Lerp (transform.position, target.position, 0.01f);
 
 transform.rotation = Quaternion.Lerp (transform.rotation, target.rotation, 0.01f);
     }


Edit -- Additional information on how to Limit Rotations. the below code uses an objects Z axis rotation to apply force if we breach our minimum or maximum.

 public float curZ;
     public float minZ = 330f;
     public float maxZ = 30f;        
     void Update () {
         
         curZ = rigidbody.transform.localEulerAngles.z;
 if(curZ > maxZ) {
                         if(transform.localEulerAngles.z > 180 && transform.localEulerAngles.z < minZ) {
                             rigidbody.AddRelativeTorque(Vector3.forward * rigidbody.mass);
                         }
                         if(transform.localEulerAngles.z < 180) {
                             rigidbody.AddRelativeTorque(Vector3.back * rigidbody.mass);
                         }
                     }
 }

// creating a float for the distance between object A and B in this case the object the scripts on from the object we set as ground.

 float distance;
 Transform ground;
 
 distance = Vector3.Distance (transform, ground.transform);

Comment
Add comment · Show 13 · 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 TheShadyColombian · Jan 21, 2015 at 12:38 PM 0
Share

i'm kind of confused. can I just stick this into my script and it'll work? I don't know what the ending position will be, so there's that.

avatar image TheShadyColombian · Jan 21, 2015 at 12:45 PM 0
Share

Can you show me manually setting up the eulerAngles, so I can see if it makes more sense to me? :\ But thank you, it's just that you're too smart for me ;D

avatar image TheShadyColombian · Jan 21, 2015 at 12:49 PM 0
Share

The way it works is that the character will be running, and the player can make him jump. when he jumps I want it to be like it's "pouncing" kind of so it needs to be facing the way I showed in the diagram, but the thing is that it's meant to bounce off of other stuff mid-air and so the height/distance parabola will reset, and I think the most productive way to make the character behave like that is by setting the x rotation relative to the vertical speed. If you have another, more useful way to do this, that'd be great.

avatar image TheShadyColombian · Jan 21, 2015 at 10:52 PM 0
Share

oh, whoops. i meant to put it so that the limit is 360º. will change the title right now!

avatar image skylem · Jan 22, 2015 at 01:26 AM 0
Share

hey yea no problem the Euler angles are the rotation values of the Transform on your Gameobject, basically the above code stops an object from rotating past 30 and -30 330 respresents -30 a simpler use example could include

 // if the objects rotation exceeds or is equal to 10 degrees
 if(rigidbody.transform.eulerAngles.x >= 10) {
 // then we lock it to 10 degrees 
 // done by creating a new Rotation value from a Vector3
 // if you fill the last field 0,0,0 the rotation would be x=0,y=0,z=0 in this case its 10 for x because thats what we're setting
     rigidbody.transform.eulerAngles = new Vector3(10,0,0);
 }
 
 

This code is just an example of a eulervalue i don't recommend using it for anything.

in answer to your other question i believe setting the rotations relative to your vertical speed is a good way to do this, u should also factor in your characters distance from the objects he is going to land on, this way the rotation of your creature will be relative to his height i added a distance check to my answer.

Show more comments

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

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

Related Questions

Flip over an object (smooth transition) 3 Answers

Multiple Cars not working 1 Answer

[C#] Rotate Turret, Only On X and Z Axis 2 Answers

Unfreezing rotation causes the position and rotation go crazy 0 Answers

How to rotate mouse addresses? 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