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 corax · Oct 19, 2013 at 07:50 AM · rigidbodytorque

Rigidbody swipe

Hi guys,

I'm on a new project not stricly gaming but physics oriented. Basically we are talking about a ball that spins left or right accordingly to the touch swipe direction and speed. The faster you swipe the faster the ball will spin. I have to use rigidbody and addTorque for this stuff and it's working pretty well.

Each swipe adds speed to the ball when it's spinning and the result is pretty realistic. (I'm using EasyTouch 3.0)

 void On_Swipe(Gesture gesture)
 {
 
 
 ballSpeed = MathF.Abs(gesture.swipeDelta);
 
 If(gesture.swipeDelta > 0)
 dir =1;
 else
 dir =-1;
 
 ball.rigidbody.addTorque(vectorUp * ballSpeed *dir);
 }
 
 void Update()
 {
 
 // we cut over time the speed so the ball will stop at some point.
 
 If(Ballspeed > 0 && dir = 1)
 ballSpeed -= friction;
 else if (Ballspeed > 0 && dir = 1)
 ballSpeed += friction;
 }

The problem comes when you have the finger stationary on the ball and want to move the ball a little bit left or right. The effect I want to recreate here is that you are actually touching the balla and you can move it left or right but the touch point stays under your finger.

So I have this code in place:

 void On_Drag(Gesture gesture)
 {
 if(gesture.pickedObject.tag == "ball" && gesture.actionTime > 0.2f)
 
 //FingerTouch Execute each frame this function.
 
 ball.transform.rotation = new Vector3(0,gesture.swipedelta*Time.deltaTime,0);
 
 //Here I must store the ball rotation speed. Will explain later why. I'm not sure this is the rot speed anyway
 
 ballSpeed = ball.rigidbody.velocity.y;
 
 }

Now if we have the finger on the ball swipe fast and lift the finger the ball must spin like when you "launch" the Wheel of the fortune (:D). So I tried to store the ball speed and use it on the rigidbody

 void On_FingerUp(Gesture gesture)
 {
 // we must be sure that we store the last speed
 
 If(gesture.swipeDelta > 0)
 dir =1;
 else
 dir =-1;
 
 ballSpeed = gesture.swipedelta.x / gesture.actionTime;
 
 ball.rigidbody.addTorque(vectorUp * ballSpeed *dir);
 }

The major problem here are that when I rotate the ball the rotation are not precise. The point you touch is not always "under you finger" when you move the ball. Moreover the "launch" feature is really bad and snappy. Any guess why? At the start seemed so simple: just replicate the feeling of touching and spinning a ball :(

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

0 Replies

· Add your reply
  • Sort: 

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

14 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

Related Questions

AddTorque not increasing relativeVelocity magnitude of a collision 1 Answer

Spinning a sphere in place causes unwanted velocity. 1 Answer

Rigidbody rotation around CenterOfMass 1 Answer

how to set initial speed of vehicle 1 Answer

Calculate force for torque by specifying a required velocity 1 Answer


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