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 Elgan · Oct 19, 2012 at 05:43 PM · 2dphysicsmaths

bit of 2D maths help: travel Arc between two points?

Hello,

I have a problem and I'm not smart enough to work out a solutions. Plus a company delivered my item to the wrong door and say its my fault...? so a bit stressed!!!!!!!

anyway,

I want to achieve a throw, a bomb between two points, and so it travels as an art from point A, to point B.

My idea was: Use half a circle, but cant even seem to get circle right today, Then just stop after 180 deg... (or the degrees between the points, which I didnt work out yet?) The points are not on a 180Deg plane. but one may be higher than the other.

..Make a circle..which is playing up?! I cant even get that right! I thought maybe the coords system? .

UNITY x, y are x, y my coords are ( 0, 0 ) is top left. (helps for my tiles mapping)...

 This is what I have been playing with for hours, , 
 
 
 [code]
     
         Vector3 centre = bombPosition; //= ( bombPosition + ( distance / 2 ));
     //    centre.x = ( bombPosition.x + ( distance.x / 2 ));
         //centre.y = ( bombPosition.y + ( distance.y / 2 ));
         
         for(float wait = 1; wait <= (  Mathf.PI ) ; wait += 0.1f)
         {
             Debug.Log(wait);
             
             yield return new WaitForSeconds (0.5f );
             //float deg = wait * Mathf.Rad2Deg;
             
             //deg = wait * (2.0f * Mathf.PI / wait);
             
             bombPosition.x = centre.x += ( 60 * Mathf.Cos ( (float) wait )  );
             bombPosition.y = centre.y -=  ( 60 * Mathf.Sin ( (float) wait)  );
             
             bomb.transform.position = bombPosition;
         }
         
     
 [/code]
Comment
Add comment · Show 4
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 · Oct 19, 2012 at 05:44 PM 0
Share

are they on the same level?

it's remarkably difficult to do this sor of thing well. Isuggest you ask on a math forum. it is not really specifically a unity question you know?

TBC you realize unity will CALCULATE EVERYTHING for you id you just throw something?

avatar image Elgan · Oct 19, 2012 at 06:00 PM 0
Share

I realise unity can do it, but I would rather do it, it shouldn't be that difficult.

$$anonymous$$aths forums might be a good idea. I thought maybe a lot of programmers come across this quite often, I know ive had to use this in the past I guess I'm just destined to ask every time :\

They are not level, so it would travel like 193 deg or something

avatar image Fattie · Oct 19, 2012 at 06:07 PM 0
Share

"but I would rather do it,"

I wonder why

not leve lis quite difficult, and, sometimes there is no solution. do you need a CERTAIN HEIGHT?

anyway good luck! maybe a math forum would be fastest

avatar image Elgan · Oct 19, 2012 at 06:40 PM 0
Share

because its not practical to use unity here, not rather, but the best tool for the job. Unity is setup totally different and for 3d, I also have no platforms or anything for it to interact with. its not a good solutions for something that cant be that hard...

5 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by phodges · Oct 19, 2012 at 06:56 PM

Rather than use a circle, how about some simple particle physics? Let's imagine the object starts of at t =0 at the origin and this is point A (it could really be anywhere, just apply the translation you need), similarly we'll imagine that the point B is aligned along the x axis (a rotation will make this true, so we're not losing this by picking a coordinate system). If the vector AB is a horizontal distance, d, away from the object and we throw it such that its horizontal speed is v_h then it will have reached the spot B (or its horizontal position) at a time

t = d / v_h

Ok. So we should throw it with an initial vertical velocity v_v, chosen such that it is magically at the right elevation at that moment. Let the difference in height between A and B be equal to h and the acceleration due to gravity be g. Measuring from A's position the height at time t will be:

s = v_v. t - 0.5. g . t^2

Rearranging a bit:

v_v = (0.5.g.t^2 + s) / t

Since we've already figured out how much time we have available to us for this arc, we've now calculated what the initial velocity should be. Back in the land of code, if we maintain a timer then we can use this to drive the bomb along this curve.

A few clarifications on my notation:

  • When I use an underscore, it should be read as an subscript, so 'v_v' is a shorthand for 'vertical velocity'

  • The caret '^' should be read as a superscript or power, so t^2 is t squared (t * t)

  • 's' is a distance, in the context of the final formula it should be interpreted as a vertical distance that the object is moving through.

  • 'g' is acceleration due to gravity in the downward direction, so for objects moving in an earth-like environment a value of 9.8 m/s^2 would be fine.

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 Elgan · Oct 19, 2012 at 10:14 PM

oh interesting, thank you

Was reading here and as you say, realized maybe the circle is the wrong approach and more like I'm needing a "parabolic arc"

I don't have time for the next days to read through your answer properly. At quick glance, I am a little confused by the format of the equation.

[code]v_v = (0.5.g.t^2 + s) / t[/code] May I ask, whats the _ represent?

and .'s?, What do they represent? +?

also I'm not sure what g is? 0.5 (.?) g - gravity?

v_v ?

http://www.mathworks.com/matlabcentral/newsreader/view_thread/278048

Thanx for the hints, check back in 3 days :)

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 phodges · Oct 20, 2012 at 06:12 AM 0
Share

Definitions added. What I've described is a parabolic arc. Please consider closing this question.

avatar image
0

Answer by Elgan · Oct 20, 2012 at 09:06 PM

thank you,

I do however have a question,

if the distance between the two positions AB is dynamic and the horizontal distance changes, the vertical distance may also change.

How can we know the initial vertical velocity in which to throw the object to make it art exactly on to position B?

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 phodges · Oct 21, 2012 at 06:34 AM 0
Share

One way to approach it is like this:

  • Pick a horizontal velocity for your object that seems 'fun' for your game

  • Use this and the first formula to calculate the time to impact

  • Feed this time into the final formula to give you the vertical velocity

avatar image
0

Answer by MountDoomTeam · Oct 21, 2012 at 07:16 AM

for normalised distance: distance x= 0 to 1, height y= 0 to 1

rising half x(0to0.5): y = (x*2)/(x*2) because for (0 to 1)/(0 to 1) is an a rising arc

falling half the same in reverse. when object gets half way, change formula from first to second. perfect parabol. or just look for parabola also and strech one out and reverse it:

PARABOLA FORMULA: https://www.google.co.uk/search?hl=en&q=parabole&biw=1184&bih=593&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.&um=1&ie=UTF-8&tbm=isch&source=og&sa=N&tab=wi&ei=9aCDUN-qKMiYhQfhnIDIDQ#um=1&hl=en&safe=off&tbm=isch&sa=1&q=parabole+formula&oq=parabole+formula&gs_l=img.3..0i10i24.6886.8770.0.8998.8.8.0.0.0.0.647.1108.0j1j1j5-1.3.0...0.0...1c.1.m3lDZEwsCh0&pbx=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.&fp=1a27f3257e169672&bpcl=35466521&biw=985&bih=650

and you could easily adapt the 3rd parabola on this page, simply move it forwards by one space and multiply will divide the height by an amount required and the distance also.

http://www.tutorcircle.com/common-graphs-tbjup.html

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 MountDoomTeam · Oct 21, 2012 at 07:28 AM

for normalised distance: distance x= 0 to 1, height y= 0 to 1

rising half x(0to0.5): y = (x*2)/(x*2) because for (0 to 1)/(0 to 1) is an a rising arc

falling half the same in reverse. when object gets half way, change formula from first to second. perfect parabol. or just look for parabola also and strech one out and reverse it:

PARABOLA FORMULA: https://www.google.co.uk/search?hl=en&q=parabole&biw=1184&bih=593&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.&um=1&ie=UTF-8&tbm=isch&source=og&sa=N&tab=wi&ei=9aCDUN-qKMiYhQfhnIDIDQ#um=1&hl=en&safe=off&tbm=isch&sa=1&q=parabole+formula&oq=parabole+formula&gs_l=img.3..0i10i24.6886.8770.0.8998.8.8.0.0.0.0.647.1108.0j1j1j5-1.3.0...0.0...1c.1.m3lDZEwsCh0&pbx=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.&fp=1a27f3257e169672&bpcl=35466521&biw=985&bih=650

modify the 3rd Formula on this page, in total you will have a 2 line simple arc formula http://www.tutorcircle.com/common-graphs-tbjup.html

Okay square root is not ideal for an arc, but it's good to know to shape control signals, probabilities of monsters appearing, distance to speed variables etc http://onemathematicalcat.org/Math/Algebra_II_obj/Graphics/fct_sqrt.gif

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

11 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

Related Questions

Lifting box 2D C# 0 Answers

2D (With Planes) Jump Script 0 Answers

How can I make a game object move in parabolic motion as if it were under gravity? 2 Answers

Physics in 2d arkanoid. Tangential and normal velocity 1 Answer

2D Physics game using sprites 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