Download

Point and click grenade

Hi,
How would I go around implementing a top-down point and click grenade (arc throw)?

The player chooses how far they want to throw the grenade (usually based on their mouse location), and the velocity changes accordingly to ensure that distance is reached.

I have tried thinking of a way but can’t seem to figure it out.

The current system I have right now is that a baseline distance has a given forward and up velocity.
Just before throwing, I divide the current distance the player wants by the baseline distance, then multiply this value with the baseline velocity.

curDis = 4m
baseDis = 7m
baseForwardVel = 7.5m/s
baseUpVel = 4m/s

multiplier = curDis / baseDis    // .57
forwardVel = baseForwardVel * multiplier     // 4.275
upVel = baseUpVel * multiplier    // 2.28

velocity = playerForward * forwardVel + playerUp * upVel

This system works but is somewhat inaccurate. At shorter distances, the grenade lands shorter than expected, and vice versa.

The only other solution I can think of is making a Vector Curve that consists of samples I have recorded myself (let’s say every 1 metre). However, I do not wish to use something that is so manual and time-consuming. For example, if I were to change the velocity, I would have to record all the samples in the Curve again. Even then, this solution still won’t be entirely accurate, just more accurate than the current solution.

Use a spline component. Add a start and end point and a middle point with height offset to it. Than use the splines tangent calculation methods to add velocity to your projectile.

Thanks for this info.
I have created a Spline Component and added some points like this.

Just before throwing the grenade, the end point is set to the location where the grenade is supposed to land.

However, I am unsure what you mean by using the tangent calculation methods to add velocity.

Also, when I attempt to change the world location of the Spline (rotation works), the actual points of the Spline are not updated. Is there a way around this? Basically, changing the starting point of the Spline and keeping the rest of the points relative?

After some testing, the grenade drops short due to gravity. Is there a way to predict for gravity or is it possible to disable gravity but somehow change velocity to mimic gravity.

If you are using the Projectile Movement you can change the velocity of the projectile in local space with this:

In the SplineComponent

there is a method called FindTangentClosestToWorldLocation

With this you are able to find the tangent (which is the direction of the tangent closest to a specific world location ).
If you use the current projectile location (in world space) as the world location you will get the direction in which your projectile should move, if you want to move it along the spline.

Normalize the tangent and multiply it with the wished speed. Than it should move along the spline.

At last you can deactivate the gravity for this projectile by changing the parameter “ProjectileGravityScale” in your ProjectileMovementComponent to 0.0

Sorry but I was unable to get it working with your solutions.

After some time, I believe it was the kinematic equations I were looking for. That took ages to find. So much physics too.

I believe by using these formulae, I am able to calculate the velocity needed either based from distance and time, or distance and peak height.

I think I’m going to try the distance and peak height variation since it should allow adjustments to be made if some roof is blocking the throw.

Material: Kinematic Equations (E03: ball problem) - YouTube