1

I am using addforce to throw object into the air, I want to instantiate a plane in position of landing point, how can I do that? I was thinking to calculate the landing point with Unity Physics API but I don't know how.

I have tried some code about projectiling but it won't help

if (other.tag == "CarPlayer")
{
    other.gameObject.GetComponentInParent<Rigidbody>().AddForce(0, 1 * power, 1 * power, ForceMode.Impulse);
}

I really need an algorithm to find actual point that the object is going to land

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

As far as I know you're gonna have to do the math yourself; Unity doesn't have a built in instant simulation of this.

There are plenty of resources online on this already, this wiki-page on Trajectory Simulation for instance, which could probably help you.

If you need to calculate the force etc (the opposite of what you're asking), have a look at this blog, where the required trajectory is calculated. Source code

The simplest answer is probably to use something like this:

public Vector3 PlotTrajectoryAtTime (Vector3 start, Vector3 startVelocity, float time) 
{
    return (start) + (startVelocity * time) + (Physics.gravity * time * time * 0.5f);
}

(Before you start explaining PEMDAS; yes, I know the parentheses aren't needed, but I think the visual grouping gives better readability, thus easier understanding of it)

Fredrik Schön
  • 4,888
  • 1
  • 21
  • 32
  • 1
    Thank you very much , I looked at this[https://answers.unity.com/questions/296749/display-arc-for-cannons-ball-trajectory.html] and i think i should go this way . – Amin Alaghband Dec 23 '18 at 12:31