Projectile Shoot trajectory in 3D problem

Hi everyone, I’m trying to move a projectile only using transform position (no rigidbody involved and no transform.translate) for hitting a target a certain position and difference of height. I menaged to work out the part regarding the 2D transform position using only the movement on Y axis as height and Z for horizontal movement. Now my question is, how I can solve the problem if my target is located at for example at the coordinate (3,8,17) and my projectile start position is (0,2,0) ? I used the Y=Yo + Voy * t -0.5 * g * t^2 and X = Xo+Vox * t and then get the time and solved the equation for Vo. In waiting for the Ben course I would like to know if someone can help me with this :wink:CatturaTraj

Hi Patrizio,

Do you already know Vector3.MoveTowards?

1 Like

Hi Nina, not used that but, if I not understand bad and it’s totally possible, this will help me on straight reach of the hitpoint right ? but if I want to shoot a projectile to certain position with bigger velocity and with a predefined angle, let’s say 55 degree I could use it ?

I would say: Test the method to see if it is doing what you want. If your idea is “a typical one”, there is always a chance that the solution has already been implemented in Unity.

I will have a look on that then, well offcurse Unity provide lot of stuff and functions but actually I was interested in some explanation on how to calculate the motion refer to X and Z axis.

Do you know vector maths? If so, you can easily move an object on the line that connects the two points in space. You move an object on its x-axis towards the target x-coordinate, and on the z-axis towards the target z-coordinate.

The “difficult” part is to stay on the aforementioned line.

Take pen and paper, draw a 2 dimentional coordinate system with x and z, define two points (P1, P2) within that coordinate system and connect these points with a line. Then draw more points onto that line, note their coordinates and compare them to the coordinates of P1 and P2. When you discover a pattern and when you are able to express that in an equation, you know how to move an object. Unity uses the same concept as you on your sheet of paper.

If you find my description too confusing, don’t worry. This subject is beyond the scope of this course anyway. You could either wait for Ben’s upcoming maths course, or you could ask our helpful community of students for advice in our official Discord chat. :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.