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"

Why does this line trace code work and how can I port it to c++

alt text alt text

For this I am using the character model from the first person template and I've slightly modified the gun and projectile.

I got the line trace portion of the code online and I understand most of it except for the camera manager part. Why use get player camera manager to get the player's location? Why not the player controller? Also, why does GetActorLocation give me the exact center of the screen, where my cross hair is? I tried moving the camera and mesh around but the trace still goes towards the center. Why isn't it affected by the positions and sizes of the mesh components?

Lastly, I am trying to make a class called Weapon (which is derived form Actor) and two derived classes: projectile and hit scan. Both will need the line trace so I want to put it in the Weapon class. But I am having trouble figuring out how to use the get player camera manager and line trace function.

In the APlayerCameraManager there is no GetActorLocation and geActortForwardVector so how do I get both of these values in c++.

For the trace, would this code be correct?

 UWorld::LineTraceSingleByChannel(...)


 



Product Version: UE 4.14
Tags:
line trace.png (138.1 kB)
line trace 2.png (122.9 kB)
more ▼

asked Feb 27 '17 at 12:13 AM in Blueprint Scripting

avatar image

Aeleon
3 1

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

1 answer: sort voted first

The player camera manager is in charge of your camera.

As such using the camera managers location / forward vector will always return the location and forward vector of the camera that is in use. Which is equal to the center of your screen and directly forward (aka where your crosshair points at).

And... did you actually try to use "GetActorLocation" on APlayerCameraManager?

A stands for Actor. So without looking at the documentation I can tell you that APlayerCameraManager inherits from AActor and should therefore absolutely implement "GetActorLocation". Since it's parent (AActor) does.

If this does not yield the results you want / if you need the currently used camera itself, you can also use "GetViewTarget" which will return you the Actor that's currently used as camera.

more ▼

answered Feb 27 '17 at 03:34 PM

avatar image

Erasio
5.9k 291 86 293

(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