# Clamp sphere trace

**URL:** <https://forums.unrealengine.com/t/clamp-sphere-trace/1213371>\
**Category:** Blueprint\
**Tags:** unreal-engine, question, Blueprint\
**Created:** [June 28, 2023, 1:12pm UTC](https://forums.unrealengine.com/t/clamp-sphere-trace/1213371 "2023-06-28T13:12:37Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![DarkEmbrace96](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DarkEmbrace96](https://forums.unrealengine.com/u/DarkEmbrace96)\
**Post date:** [June 28, 2023, 1:12pm UTC](https://forums.unrealengine.com/t/clamp-sphere-trace/1213371/1 "2023-06-28T13:12:37Z")

</div>

Hi,

Is it possible to clamp a sphere trace with this setup?

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/c/8/2c8220a7a747eac75ebf0c0ec4f992e9c93a1971.png)

What I want is for the player to only pickup objects that are infront of the player. The camera freely rotates when not moving so currently you can pick stuff up behind you, so is there a way to prevent the trace going behind the player?

---

<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:** [June 28, 2023, 1:38pm UTC](https://forums.unrealengine.com/t/clamp-sphere-trace/1213371/2 "2023-06-28T13:38:26Z")

</div>

Sounds like you want to use Player Forward instead of Camera Forward. Or do you want to pick up stuff in an arc in front of the player only but using the camera to look at it?

---

<div class="post-metadata">

**Author:** ![DarkEmbrace96](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DarkEmbrace96](https://forums.unrealengine.com/u/DarkEmbrace96)\
**Post date:** [June 28, 2023, 1:48pm UTC](https://forums.unrealengine.com/t/clamp-sphere-trace/1213371/3 "2023-06-28T13:48:09Z")

</div>

Yeah thats what I was hoping for, some sort of arc in front of the player only. I did try the forward vector of the player but it won’t move with the camera so not exactly what I’m looking for

---

<div class="post-metadata">

**Author:** ![SpectreKelevra](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/spectrekelevra/32/723050_2.png) [@SpectreKelevra](https://forums.unrealengine.com/u/SpectreKelevra)\
**Post date:** [June 28, 2023, 1:50pm UTC](https://forums.unrealengine.com/t/clamp-sphere-trace/1213371/4 "2023-06-28T13:50:23Z")

</div>

So you want it to move with the camera but stay in the FOV of the player character?  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/b/a/bbaed961961e862f86caff2504be205bd1236253.png)

As in stay within the filled portion?

---

<div class="post-metadata">

**Author:** ![DarkEmbrace96](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DarkEmbrace96](https://forums.unrealengine.com/u/DarkEmbrace96)\
**Post date:** [June 28, 2023, 1:51pm UTC](https://forums.unrealengine.com/t/clamp-sphere-trace/1213371/5 "2023-06-28T13:51:15Z")

</div>

yep something like that

---

<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:** [June 28, 2023, 2:01pm UTC](https://forums.unrealengine.com/t/clamp-sphere-trace/1213371/6 "2023-06-28T14:01:50Z")

</div>

Try this:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/b/9/eb958d611321d2e814c38462d149b1f36f44ae1c.png)

---

<div class="post-metadata">

**Author:** ![SpectreKelevra](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/spectrekelevra/32/723050_2.png) [@SpectreKelevra](https://forums.unrealengine.com/u/SpectreKelevra)\
**Post date:** [June 28, 2023, 2:07pm UTC](https://forums.unrealengine.com/t/clamp-sphere-trace/1213371/7 "2023-06-28T14:07:21Z")

</div>

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/6/5/665da3b528a759c3a7fa4422bd16167e7f0f7a27.png)

This would work, with the benefit of having a max range that you can edit whenever.

I set it to 0.25 and it gives me a nice quarter circle.

---

<div class="post-metadata">

**Author:** ![SpectreKelevra](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/spectrekelevra/32/723050_2.png) [@SpectreKelevra](https://forums.unrealengine.com/u/SpectreKelevra)\
**Post date:** [June 28, 2023, 2:08pm UTC](https://forums.unrealengine.com/t/clamp-sphere-trace/1213371/8 "2023-06-28T14:08:54Z")

</div>

Does Vector 2D automatically ignore Z?

---

<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:** [June 28, 2023, 2:09pm UTC](https://forums.unrealengine.com/t/clamp-sphere-trace/1213371/9 "2023-06-28T14:09:15Z")

</div>

Mhm:

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/7/d/f7d5417557e7c8c47592551c9aef85e620d3e5fa.png)

---

<div class="post-metadata">

**Author:** ![SpectreKelevra](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/spectrekelevra/32/723050_2.png) [@SpectreKelevra](https://forums.unrealengine.com/u/SpectreKelevra)\
**Post date:** [June 28, 2023, 2:09pm UTC](https://forums.unrealengine.com/t/clamp-sphere-trace/1213371/10 "2023-06-28T14:09:42Z")

</div>

Interesting, very useful, thank you.

---

<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:** [June 28, 2023, 2:11pm UTC](https://forums.unrealengine.com/t/clamp-sphere-trace/1213371/11 "2023-06-28T14:11:14Z")

</div>

Not sure how well will my suggestion work if OP has a camera socket / target offset. Worst case scenario we can do a normal full trace, work with the resulting hit location and reject the undesired results.

---

<div class="post-metadata">

**Author:** ![DarkEmbrace96](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DarkEmbrace96](https://forums.unrealengine.com/u/DarkEmbrace96)\
**Post date:** [June 28, 2023, 2:45pm UTC](https://forums.unrealengine.com/t/clamp-sphere-trace/1213371/12 "2023-06-28T14:45:39Z")

</div>

How do you convert this pin to have 3 outputs?  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/a/9/fa9fc20db808e33448f2d663cea2ffccf71c7520.png)

---

<div class="post-metadata">

**Author:** ![SpectreKelevra](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/spectrekelevra/32/723050_2.png) [@SpectreKelevra](https://forums.unrealengine.com/u/SpectreKelevra)\
**Post date:** [June 28, 2023, 2:46pm UTC](https://forums.unrealengine.com/t/clamp-sphere-trace/1213371/13 "2023-06-28T14:46:13Z")

</div>

Break vector to output 3 separate floats.  
Make vector to input 3 separate floats.

![Animation](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/b/3/3b350d85374823d9de06efde24e9ef2c1ab529af.gif)

---

<div class="post-metadata">

**Author:** ![DarkEmbrace96](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DarkEmbrace96](https://forums.unrealengine.com/u/DarkEmbrace96)\
**Post date:** [June 28, 2023, 2:52pm UTC](https://forums.unrealengine.com/t/clamp-sphere-trace/1213371/14 "2023-06-28T14:52:16Z")

</div>

what about plugging the other vector in like the first graph, I don’t seem to have that option

---

<div class="post-metadata">

**Author:** ![SpectreKelevra](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/spectrekelevra/32/723050_2.png) [@SpectreKelevra](https://forums.unrealengine.com/u/SpectreKelevra)\
**Post date:** [June 28, 2023, 2:55pm UTC](https://forums.unrealengine.com/t/clamp-sphere-trace/1213371/15 "2023-06-28T14:55:09Z")

</div>

Oh, I misunderstood your question.

That is a subtract node, and as long as the pin is unplugged you can “Split struct pin” to separate it into its components (In the case of vector, it becomes 3 floats)  
 ![Animation2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/6/f/e6fe5e9412d4fa6fdb354fc1ecbe2ffbe15366f3.gif)

---

<div class="post-metadata">

**Author:** ![SpectreKelevra](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/spectrekelevra/32/723050_2.png) [@SpectreKelevra](https://forums.unrealengine.com/u/SpectreKelevra)\
**Post date:** [June 28, 2023, 3:07pm UTC](https://forums.unrealengine.com/t/clamp-sphere-trace/1213371/16 "2023-06-28T15:07:34Z")

</div>

FYI, this only applies to left and right turning, to add vertical look, just make a third “in range” node for the Z float.

and note, it will give you a hard edge box with a curved face (if that matters at all, you won’t feel the difference between that and a cone, and this is cheaper than cone maths).  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/8/d/d8d425b3aa195453d8c4b66fcd59cf4ef68db089.png)

---

<div class="post-metadata">

**Author:** ![DarkEmbrace96](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DarkEmbrace96](https://forums.unrealengine.com/u/DarkEmbrace96)\
**Post date:** [June 28, 2023, 3:18pm UTC](https://forums.unrealengine.com/t/clamp-sphere-trace/1213371/17 "2023-06-28T15:18:17Z")

</div>

Thanks for all the suggestions, but I can’t seem to get it to work, I don’t get a sphere trace at all now, would could I be missing?

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/c/b/2cbbe20af9305cf33f11c6540bb7f77b9d77d787.png)

---

<div class="post-metadata">

**Author:** ![SpectreKelevra](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/spectrekelevra/32/723050_2.png) [@SpectreKelevra](https://forums.unrealengine.com/u/SpectreKelevra)\
**Post date:** [June 28, 2023, 3:23pm UTC](https://forums.unrealengine.com/t/clamp-sphere-trace/1213371/18 "2023-06-28T15:23:09Z")

</div>

You’re subtracting location and forward vector.

You can only subtract Two forward vectors.

A location could be 500, 200, 20.  
While a forward vector is limited between -1 → 1.

Use the actor forward vector - camera forward vector to plug into the branch.

Then Actor/camera location as start, and (actor/camera location + (camera forward vector \* range)) as End.

---

<div class="post-metadata">

**Author:** ![DarkEmbrace96](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DarkEmbrace96](https://forums.unrealengine.com/u/DarkEmbrace96)\
**Post date:** [June 28, 2023, 3:38pm UTC](https://forums.unrealengine.com/t/clamp-sphere-trace/1213371/19 "2023-06-28T15:38:59Z")

</div>

thankyou, that works great, love the flexibility for changing the angle that will come in handy. Do you know how to make a sphere trace taller without making the radius huge?

---

<div class="post-metadata">

**Author:** ![SpectreKelevra](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/spectrekelevra/32/723050_2.png) [@SpectreKelevra](https://forums.unrealengine.com/u/SpectreKelevra)\
**Post date:** [June 28, 2023, 3:46pm UTC](https://forums.unrealengine.com/t/clamp-sphere-trace/1213371/20 "2023-06-28T15:46:12Z")

</div>

A sphere trace is just a sphere that moves from Start to End

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/2/a/92a7806d8021738821f86b96261470654a0e6124.jpeg)

The distance L is the length of the trace, and the sphere radius r is the thickness of the “rod”

You can increase L by increasing your “Local interact range” variable, but you cannot increase one dimension of the sphere to make it an ellipse, if that’s what you mean by taller, you can only increase the overall size of the sphere and by extension the thickness of the pole.

[Next page](https://forums.unrealengine.com/t/clamp-sphere-trace/1213371.md?page=2)
