Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 vanhalen17 · Jun 10, 2017 at 02:29 PM · transform

Rotating a football with a spiral...

Hello,

I have a football I'd like to throw and while it is in the air to have its upward direction pointing in the way of its velocity, while rotating (spiraling) around that axis.

Here is my code that points it to the velocity, but not rotating spiral: void Update () { if (thrown) { model.up = body.velocity; model.Rotate(Vector3.up, 500 * Time.deltaTime); } }

Thank you community!

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by toddisarockstar · Jun 10, 2017 at 09:17 PM

assuming you modeled your football with the ends up and down. you would only apply the velocity to x and z. and spin on the y axis.

this should work if you put it in update:

 float spin;
 float spinspeed;
 Vector3 facing;
 Rigidbody rb;

 void Start(){
  rb = GetComponent<Rigidbody>();
 spin = 1f;
 spinspeed=20f; //adjust for spin speed of ball
 }
 
 void Update () {
              facing=Quaternion.LookRotation(rb.velocity).eulerAngles;
             spin += Time.deltaTime * spinspeed;
             if(spin>360f){spin=spin-360f;}


                  transform.eulerAngles = new Vector3 (facing.x, spin, facing.z);

                  // if you modeled the ball left and right use this instead:
                  // transform.eulerAngles = new Vector3 (spin, facing.y, facing.z);

                  // if you modeled the ball forward and back use this instead:
                  // transform.eulerAngles = new Vector3 (facing.x, facing.y, spin);

 
 }
  
 
 



Comment
Add comment · 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
0

Answer by shadowpuppet · Jun 12, 2017 at 09:13 AM

why not just have an animation component on the football that loops itself spiraling

Comment
Add comment · 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
0

Answer by tMahon · Jun 12, 2017 at 09:14 AM

You could also use a WheelCollider Component attached to the football and just add motor torque to it. It seems a little counter-intuitive, but if you're like me, and you don't like working with Quaternions, and you have a Rigidbody on your football, this is a good workaround. It's really quite simple, just add a wheel collider component to an empty GameObject child to the Football with its Mesh Collider or whatever it's using. From there just add motor torque to the wheel.

 using UnityEngine;
 
 public class ThrowFootball : MonoBehaviour {
     [SerializeField]
     WheelCollider spiralCollider;
     [SerializeField]
     MeshRenderer footballMesh;
     [SerializeField]
     float throwTorque = 100f;
 
     // Use this for initialization
     void Start () {
         ThrowBall();
     }
 
     private void ThrowBall()
     {
         spiralCollider.motorTorque = throwTorque;
         gameObject.GetComponent<Rigidbody>().AddForce((transform.up - transform.forward));
     }
 
     // Update is called once per frame
     void Update () {
         Vector3 pos = new Vector3();
         Quaternion quat = new Quaternion();
         spiralCollider.GetWorldPose(out pos, out quat);
         footballMesh.transform.position = pos;
         footballMesh.transform.rotation = quat;
     }
 }
 


Comment
Add comment · 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

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

Vector3 sets to different coordinates than specified 1 Answer

How to only instantiate objects once? 1 Answer

Vertex transformation - MissingFieldException error 2 Answers

When I add force to rigidbody it doesn't keep it location 0 Answers

How can I move an object a certain distance, once? 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