- Home /
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]
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?
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
"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
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...
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.
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 :)
Definitions added. What I've described is a parabolic arc. Please consider closing this question.
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?
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
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:
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.
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:
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
Your answer
![](https://koobas.hobune.stream/wayback/20220613082629im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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