Clamp sphere trace

Hi,

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

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?

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?

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

So you want it to move with the camera but stay in the FOV of the player character?
image

As in stay within the filled portion?

yep something like that

Try this:

2 Likes

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.

2 Likes

Does Vector 2D automatically ignore Z?

Mhm:

image

1 Like

Interesting, very useful, thank you.

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.

How do you convert this pin to have 3 outputs?
image

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

Animation

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

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

2 Likes

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

1 Like

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?

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.

1 Like

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?

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

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.