- Home /
Oblique launch problem
Hey everyone. Weeks ago I posted here about the same subject. I want to make some kind of oblique launch, from start to goal. There's no problem in this because I can just try some things using values based on distance between start and goal or also use high school physics, but my problem is to make the projectile go forward. I'm not managing to 'join' the velocity that the projectile need to get to the goal with the forward vector3 of the empty who launch the projectile.
If I have something like this:
Vector3 emptyForward = myEmpty.forward;
Vector3 velocity = new Vector3(// some maths here to find a nice vec3 for the velocity, whatever);
So now, how I'll procede to 'join' emptyForward with velocity? Remembering that the velocity Vec3 will be applied to the rigidbody.
rigidbody.velocity = velocity;
Here's an image of the disared path:
Thanks from now!
Just use high-school physics. Imagine it in a 2-dimensional plane, and then use 'transform.TransformDirection' to convert in into a 3-dimensional vector!
Good! TransformDirection should work! What kind of way should I use to get the distance? (goal - start).sqr$$anonymous$$agnitude or (goal.x - start.x, ....) Each one will produce different results?
sqr$$anonymous$$agnitude gives you the distance squared, which isn't exactly what you want. I'd use Vector3.Distance(start, end) for the total distance, but in this case that's not exactly what you want- you need to work out the 2-dimensional vector (for the high-school physics bit). In this case, I'd rotate the transform so that it points towards the target point (make sure it doesn't point up or down, so adjust the y-axis of the target point to fake it being level with the transform), then use InverseTransformPoint to find the vector to the actual target. In doing so, you should be able to discard the x-coordinate, and do your calculation using the y-coord as the height, and the z-coord as the distance. Having calculated the vector with that, use TransformDirection to get the vector back into world coordinates to fire the projectile!
Your answer
Follow this Question
Related Questions
Apply rigid body force in opposite direction of collider 1 Answer
Changing 1 parameter of rigidbody.velocity (Vector3) 2 Answers
How to apply a force after launching the player? 0 Answers
Constrain rigidbody movement to spline at high speeds / sharp curves 3 Answers
Rigidbody object intersection 0 Answers