# Projectile trajectory

**URL:** <https://forums.unrealengine.com/t/projectile-trajectory/2456993>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question\
**Created:** [April 14, 2025, 8:26pm UTC](https://forums.unrealengine.com/t/projectile-trajectory/2456993 "2025-04-14T20:26:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![user20785](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@user20785](https://forums.unrealengine.com/u/user20785)\
**Post date:** [April 14, 2025, 8:26pm UTC](https://forums.unrealengine.com/t/projectile-trajectory/2456993/1 "2025-04-14T20:26:13Z")

</div>

Hey

Trying to implement trajectory for projectiles. And encountered a problem

 ![trace](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/7/c/37ce54e3167376460c95dffbf1a5010825a9d1b8.png)

Purple curve it is surface, begin it is actor location(projectile spawn point) and end it is mouse click location. Now, projectile moves on the green line.  
I want to set projectile trajectory on the blue tangent line, but doesnt know how to detect blue point. Does engine have an effective ways to detect it?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [April 15, 2025, 8:55am UTC](https://forums.unrealengine.com/t/projectile-trajectory/2456993/2 "2025-04-15T08:55:37Z")

</div>

> [@user20785](#):
>
> Does engine have an effective ways to detect it?

No.

> [@user20785](#):
>
> Purple curve it is surface

If you have no spline that describes the surface, you may need to rely on tracing and calculating right vector of normal. if you had a spline, you could read the tangent directly.

* * *

So we’re on the same page: you want a projectile to follow the curvature of a surface, right?

---

<div class="post-metadata">

**Author:** ![user20785](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@user20785](https://forums.unrealengine.com/u/user20785)\
**Post date:** [April 15, 2025, 9:18am UTC](https://forums.unrealengine.com/t/projectile-trajectory/2456993/3 "2025-04-15T09:18:26Z")

</div>

Curvature of surface it is not necessarily. Enough just a straight line between spawn point and highest visible point relative to spawn point

As example:

 ![trj](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/2/d/22daa9aa066d39c547868069d52d7a2cf9a12714.png)

I have implemented iterative approach, incrementing Z axis and using line trace. But efficiency is questionable(when number of projectiles per second too high)

---

<div class="post-metadata">

**Author:** ![user20785](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@user20785](https://forums.unrealengine.com/u/user20785)\
**Post date:** [April 16, 2025, 1:50pm UTC](https://forums.unrealengine.com/t/projectile-trajectory/2456993/4 "2025-04-16T13:50:20Z")

</div>

I have changed main idea, and now we looking for not tangent point, but vector perpendicular to normal of traced hit point, based on source direction, so func looks like this:

```auto
bool GetDirectionNormal(FVector& newDirection, const FVector spawnPoint, const FVector clickPoint) {
	auto world = GetWorld();
	if (world == nullptr) {
		return false;
	}
	
	FHitResult hitResult;
	if (!world->LineTraceSingleByChannel(hitResult, spawnPoint, clickPoint, ECollisionChannel::ECC_Visibility)) {
		return false;
	}
	
	auto oldDirection = (clickPoint - spawnPoint).GetSafeNormal();
	auto projection = FVector::DotProduct(oldDirection, hitResult.ImpactNormal) * hitResult.ImpactNormal;
    
	newDirection = (oldDirection - projection).GetSafeNormal();
	
	return true;
}

```

And result(it is not so good when we talk about too high objects):

 ![fin_traj_](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/6/1/c612961897e522e11e3c05a814bebccfb91e4538.jpeg)

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [May 16, 2025, 1:50pm UTC](https://forums.unrealengine.com/t/projectile-trajectory/2456993/5 "2025-05-16T13:50:37Z")

</div>

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