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 Ethan91 · Sep 29, 2012 at 09:00 PM · physicsforcenewbiebouncemotion

Force in Circular Motion

Hi Everyone

So I'm trying to make a ball moving in half circular motion ( that is when it enters a zone, it will be moving in half circular motion to exit that zone, kindda like soft bouncing ). What I do is, let's say my Character is moving straight. Then in order to achieve this circular motion, I apply a constant force that is perpendicular to the Character.rigidboy.velocity ( and I need to update this new constant Force every single frame ). So, in Fixedupdate, I have a function to calculate my new Force vector, and a function to addForce to my Character. However, after doing this, my characeter seems to fly away in insense speed. I wonder what have I done wrong ? Thanks a lot for your time.

Comment
Add comment · Show 5
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 Fattie · Sep 30, 2012 at 02:18 PM 0
Share

your basic idea is correct! well done

very likely you just have some bug.

simply plant a "marker" (an empty game object) at the center of the circle.

(if it is in the same place every time, just do that. if it is in a different place each run, set it dynamically when you enter the "turn zone")

Simply make the force always point towards that marker point.

to be clear unity HAS a thingy called "constant force". if you were referring to that, don't use it. delete that component. simply set the force each time (pointing at the marker as discussed) in each frame.

avatar image Ethan91 · Sep 30, 2012 at 11:15 PM 0
Share

Hi Fattie, Im not quite sure what do you mean by set the force without using constant force, but yes, I do use rigidbody.addForce which I believe to be constant Force. I don't know that there exists another way around ?

avatar image Fattie · Oct 01, 2012 at 05:30 AM 0
Share

look in the menus. component -> physics -> ConstantForce

it's a component, like adding camera, box collideer or whatever!

anyway, it sounds like you're NOT using ConstantForce. so that's fine.

avatar image Dreamblur · Oct 01, 2012 at 07:24 AM 0
Share

It's either an issue of force vs. impulse or an over-calculated force. I reckon it's the latter.

avatar image Fattie · Oct 01, 2012 at 07:30 AM 0
Share

"I apply a force that is perpendicular to the Character.rigidboy.velocity" --

that's incorrect, as I mention Ethan you simply apply the force towards a point in the center of the circle you want the object to travel around

it's exactly like swinging something with a string- you're applying the force of the string. it's just a line of code

you surely know the formulas involved from basic high school arithmetic, you can google up hundreds of pages!

http://www.school-for-champions.com/science/force_centripetal.htm

Alternately if you don't want to use physics, Aldo has explained beautifully how to "animate the velocity"

Just a note, all of this is generally useless in real-world video games because it does not actually "steer" the object around - it's why cars are so hard to simulate properly.

you say it's a ball so you might get away with it, but it will always be pointing the wrong way

incidentally you say "kindda like soft bouncing" - I have no idea what that means.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by aldonaletto · Oct 01, 2012 at 07:11 AM

Unfortunately, physics isn't that easy: applying a force produces an acceleration, which gradually increase the velocity in its direction over time. The results are hard to predict, and probably far away from what you expect - unless you have time enough to wait until the ball trajectory stabilizes in an elliptical orbit, at God-knows-what velocity.
If you really want a semi circular trajectory, it's better to twist the rigidbody velocity each FixedUpdate while the ball is inside this zone. You could create an empty object, add a box collider and check Is Trigger, then adjust the collider dimensions and center to define the capture zone, and finally tag it as "CircularZone", for instance. You could do the magic in the character script, with something like this:

 private var cZone: Transform;
 private var rBody: Rigidbody;

 function Start(){
     rBody = gameObject.GetComponent.<Rigidbody>();
 }
 
 function OnTriggerEnter(other: Collider){ // entering circular zone
   if (other.tag == "CircularZone") cZone = other.transform;
 }
 
 function OnTriggerExit(other: Collider){ // exiting circular zone:
   if (cZone == other.transform) cZone = null; // null 
 }
 
 function FixedUpdate(){
   if (cZone){
     // calculate the direction ball -> zone center:
     var vCenter = cZone.position - rBody.position;
     // find the axis to orbit around:
     var vAxis = Vector3.Cross(rBody.velocity, vCenter);
     // find the new velocity direction:
     var vVel = Vector3.Cross(vCenter, vAxis).normalized;
     // twist rigidbody.velocity to the new direction:
     rBody.velocity = vVel * rBody.velocity.magnitude;
   }
 }

Comment
Add comment · Show 1 · 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 BillyBobBeavis · Nov 04, 2018 at 05:19 AM 0
Share

Thank you. This may be very useful to me and I don't have the experience to invent code like this.

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

How To Freeze An Object Motion? 3 Answers

Balls bouncing off each other 0 Answers

how to change physics material of a colider in runtime 5 Answers

Character Controller meets Rigidbody 1 Answer

add force to object that has 2 different rigid bodies 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