- Home /
2d - calculating velocity needed to pass by point
Knowing the initial position and the point to reach position i need to find the velocity needed to pass by the point. i am not using rigid body object is only affected by gravity if someone could perhaps guide me in the right direction to fix this problem that would be great thanks. i need to calculate the minimum velocity possible that can pass by the "Point To Reach" as in the image.
I don't know what you're problem actually is, you don't really state it. You don't have to have a specific velocity to pass a point... What are you even trying to do??? Are you using rigidbodies? Please be more descriptive, and we'll be happy to help.
i am currently going through this page trying to find something :- http://en.wikipedia.org/wiki/Projectile_motion
"i am not using rigid body object is only affected by gravity"
If an object is affected by gravity, it is a rigidbody.
You would pretty much need to test this out with different values, because you need to use AddForce depending on the current Gravity of your world. This would be a force you would only apply at the start. Here's a basic example of how to make an object "Jump". This would require a rigidbody component. Each method, variable, parameter I use here can be looked up on the Unity Script Reference, which will help you better understand.
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Rigidbody))]
public class Example : $$anonymous$$onoBehaviour
{
void Awake()
{
rigidbody.AddForce((Vector3.up + Vector3.right) * 5, Force$$anonymous$$ode.Impulse);
}
}
you misunderstood my question - its my fault i am not really sure how to explain it very well. here is a similar question http://answers.unity3d.com/questions/398953/calculate-initial-velocity-to-reach-destination-ba.html but i dont have the Time variable so this cannot work for me.
Answer by Wuzseen · Aug 14, 2013 at 04:34 AM
This would be easier to calculate without rigidbodies--which you're apparently not using, so yay. You can simply do some interpolation along a 3 point hermite curve where Initial Position is the first control point, point to reach the second, and destination the third and final. You would then interpolate over this equation. It basically makes a function of a variable t with the domain t = 0 to 1. The result of this function is the position along your interpolation curve.
This is not a small amount of code, but it isn't actually that hard to implement: http://en.wikipedia.org/wiki/Cubic_Hermite_spline
The wikipedia article is terrible at explaining how to do it pro grammatically so I would suggest doing your own research. Like I said it's quite a bit of code--this is why things like iTween and what not exist.
EDIT: If you are simulating gravity with your own script, be sure to turn it off while you do this!
thank you for your answer the idea seem possible but i hoped for something as simple as shooting a projectile with the calculated velocity, i will use this with iTween path if i cant find anything more simple. thank you.