Initial Velocity in Vector3 format - non equal height

In summary, to accurately hit a target in a 2D landscape, you can use the classic two-dimensional trajectory equation to calculate the initial velocity required. This equation takes into account factors such as gravity, starting and target coordinates, and launch angle.
  • #1
dklompmaker
1
0
I have been toiling over this for the last three weeks. I am programming a tank to fire at a target. The target can be all over the landscape up, down left right. Currently I have the turret turn to face the target turning the problem into a 2d equation. So I need help finding the right equation for initial velocity to hit the target.

Basically I am doing the following.

tv = target.transform.position - transform.position; // This is a vector direction to my target
var g = -9.8; // Gravity
var r = Mathf.Abs(tv.z); // The range or x to my target
var a = Mathf.Sin(90); /
var v = Mathf.Sqrt((r * g ) / a); // Finally get my velocity and return it
return v;

I know these equations are wrong but I am having a hard time trying to figure out how to account for height differences, and get the correct initial velocity to fire the bullet to hit the target.

Thank you for your help!
 
Physics news on Phys.org
  • #2
The equation you are looking for is the classic two-dimensional trajectory equation. It is derived from Newton's law of motion and allows us to calculate the initial velocity required for a projectile to reach a specified target. The equation is as follows:v₀² = (g * x₀²) / (2 * (y₁ - y₀ + (x₁ - x₀) * tan(θ)))where v₀ is the initial velocity, g is the acceleration due to gravity, x₀ and y₀ are the starting coordinates, x₁ and y₁ are the target coordinates, and θ is the angle of launch. In your case, you are trying to find the initial velocity required to hit a target at some distance away, so the equation simplifies to:v₀² = (g * x²) / (2 * (tan(θ)))Hope this helps!
 
  • #3


I would suggest using the kinematic equations of motion to solve this problem. The initial velocity in vector3 format can be calculated as follows:

1. Determine the displacement vector (tv) from the tank to the target.

2. Decompose the displacement vector into its x, y, and z components.

3. Use the horizontal component of the displacement (tv.x) and the time it takes for the projectile to reach the target (t) to calculate the initial velocity in the x direction using the equation: v0x = tv.x/t.

4. Use the vertical component of the displacement (tv.y) and the time it takes for the projectile to reach its maximum height (t/2) to calculate the initial velocity in the y direction using the equation: v0y = tv.y/(t/2) + 0.5gt.

5. Use the initial velocity in the x and y directions to calculate the magnitude of the initial velocity using the equation: v0 = √(v0x² + v0y²).

6. Use the initial velocity in the z direction (tv.z) and the time it takes for the projectile to reach its maximum height (t/2) to calculate the initial velocity in the z direction using the equation: v0z = tv.z/(t/2) + 0.5gt.

7. Combine the three components of the initial velocity (v0x, v0y, v0z) to get the final initial velocity in vector3 format.

It's important to note that this calculation assumes a constant gravitational acceleration (g) and no air resistance. If these factors are present, the equations may need to be adjusted accordingly.

I hope this helps guide you in finding the correct equation for initial velocity to hit the target. Good luck with your programming!
 

1. What is initial velocity in vector3 format?

Initial velocity in vector3 format refers to the initial speed and direction of an object in three-dimensional space. It is represented by a vector with three components (x, y, z) that indicate the magnitude and direction of the velocity.

2. How is initial velocity in vector3 format calculated?

The initial velocity in vector3 format can be calculated using the formula: v = (x, y, z), where x, y, and z are the respective components of the velocity vector. This formula takes into account both the speed and direction of the object.

3. What is the difference between equal and non-equal height in initial velocity?

Equal height refers to objects that are launched or moving at the same height, while non-equal height refers to objects that are launched or moving at different heights. In the context of initial velocity, this means that the y component of the velocity vector will be the same for objects with equal height, but different for objects with non-equal height.

4. Can initial velocity in vector3 format be negative?

Yes, initial velocity in vector3 format can be negative. The direction of the velocity vector is represented by its sign, with positive values indicating movement in the positive direction and negative values indicating movement in the negative direction.

5. How does initial velocity in vector3 format affect an object's trajectory?

The initial velocity in vector3 format plays a crucial role in determining an object's trajectory. The magnitude and direction of the velocity vector will determine the path that the object takes, and changes in these values can result in different trajectories. Additionally, the y component of the velocity vector can affect the height of the object's trajectory.

Similar threads

Replies
27
Views
1K
Replies
11
Views
2K
  • Introductory Physics Homework Help
Replies
7
Views
90
Replies
8
Views
1K
  • Introductory Physics Homework Help
Replies
5
Views
287
  • Introductory Physics Homework Help
Replies
8
Views
1K
Replies
3
Views
3K
  • Introductory Physics Homework Help
Replies
8
Views
1K
  • Introductory Physics Homework Help
Replies
11
Views
2K
Replies
2
Views
3K
Back
Top