x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

simple raycast from camera

I have a blueprint question for the experts,

I'm trying to recreate a very simple game I made in unity that involved picking up objects and stacking/placing them on top of each other to reach obstacles. I currently have it so that I can pickup objects (this is all in first person), however I feel I'm doing it in an extremely hacky way. I'm using a long thin box component attached to my first person camera and using that as a pseudo raycast.

My question is... Using blueprint, how do I do a simple raycast that shoots from my camera to wherever its looking (and designate the length of the ray) so that I can get results, designate valid targets, etc?

Thanks!

Product Version: Not Selected
Tags:
more ▼

asked Mar 22 '14 at 11:31 PM in Blueprint Scripting

avatar image

venain
38 5 12 9

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

5 answers: sort voted first

Trace

In UE4 they are called traces!

You will want to

  1. Get Player Controller

  2. Get Focal Location from the PC

  3. Get Control Rotation of the PC

then you want to do a Trace as follows

start = PC Location End = PC Location + 12000 * ControlRotation As a Vector

You need to convert the control Rotation into Vector using appropriate BP nodes

Easier Way

There might be an easier way, but definitely look up informaton on

Traces

:)

Rama

more ▼

answered Mar 22 '14 at 11:40 PM

avatar image

Rama
10.6k 446 343 1085

avatar image Ben Halliday STAFF Mar 22 '14 at 11:44 PM

Hey venain,

Rama is correct, Trace Responses are how UE4 handles ray casting. There's some information on Collision Responses you might find useful here: https://docs.unrealengine.com/latest/INT/Engine/Physics/Collision/index.html

Hope that helps!

Ben Halliday

avatar image venain Mar 23 '14 at 12:01 AM

Hey thanks for the great info Rama and Ben!

However, how do I get the Focal Location from the PC? The only "Focal" nodes I could find had to do with AI controllers...

Thanks again!

avatar image Rama Mar 23 '14 at 11:02 PM

Mouse Loc and Dir

This is what you are probably going to want to use ultimately anyway

to do the trace, the end point should be

Mouse Location + Mouse Dir * 24000

or whatever trace length you want :)

alt text

mouselocanddir.jpg (58.4 kB)
avatar image venain Mar 24 '14 at 06:09 AM

I tried this setup and the result is the same, I have to add/multiply by an extremely high number or else the trace doesn't shoot straight out of the camera, but a downward angle.

I'm currently just storing the hit object location and comparing it with my player controllers location to do a distance check, so it's not the biggest deal... But I would like to know how to do a small length trace for future uses, but I'm stumped at this point:\

avatar image Rama Mar 24 '14 at 06:34 AM

Please post your whole BP graph :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I was able to fix this, the problem was just the order of operations. Just make sure you multiply the forward vector of your start point by whatever length you want it to be, then add that result to the world location of your start point. I attached a graph that points this out, thanks for the help everyone!alt text

tracebp.jpg (410.3 kB)
more ▼

answered Mar 24 '14 at 10:10 AM

avatar image

venain
38 5 12 9

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I was able to do this using the camera world location as the start point and everything else as rama said, I'm just curious though, why exactly add 12000 to the starting location? I tried playing with this number and it just seems that the ray isn't shooting out straight at lower numbers, which means using this method I can't have a really short ray distance, is that normal?

more ▼

answered Mar 23 '14 at 10:01 AM

avatar image

venain
38 5 12 9

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

12000 is just a long trace out into the world (120m). If you use a shorter trace, it should work, but it just might not be far enough to hit the thing you want.

more ▼

answered Mar 23 '14 at 10:27 AM

avatar image

JamesG STAFF
1.3k 8 8 32

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

unfortunately, if I add anything other than 10000-12000, the trace is no longer shooting straight out, but rather angled down towards the ground.

more ▼

answered Mar 23 '14 at 10:52 AM

avatar image

venain
38 5 12 9

avatar image JamesG STAFF Mar 23 '14 at 01:43 PM

That sounds strange, could you post a screenshot of your logic?

avatar image venain Mar 23 '14 at 10:41 PM

Sure, here's the trace part of my bp, it's just being activated by the On-Tick event.

alt text

tracebp.jpg (328.0 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question