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"

[Discussion] Interacting with environment

Hello. I started working in Unreal and especially game development pretty recently. So interacting with environment is a really important part of games. And mostly all the interactions will be done with one key i.e. "E" key. What kind of system or technique do you guys implement to manage interacting with environment.

This thread is for learning. I will appreciate any kind of knowledge passed on by you guys.

Regards

Product Version: UE 4.12
Tags:
more ▼

asked Sep 09 '16 at 06:54 AM in Everything Else

avatar image

Suhaib Rehman
110 5 7 15

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

2 answers: sort voted first

This may be by no means, the most efficient approach, but it works and there is tutorial support on how to do it. My character class does a line trace directly out from the camera (thus the reticule) for the distance I use as a item/information discovery distance. If there is a hit, I check if the actor that was hit is of a class that wants to be discovered. If it is, the "Press E to" message is presented to the player.

The GetWorld->LineTraceSingleByChannel returns an FHitResult. I interrogate the FHitResult (named "Hit" in this example as follows: if(Hit.GetActor()->IsA(AFlightPawn::StaticClass())) {//this is flying class, ask if player wants to fly it}

After you've done the trace, you can interrogate for many types of classes. In my case that would be my wheeled vehicle class, flying vehicle class, weapon class, door class, elevator class, and item class. Then I have one additional class that registers as a valid hit, but does not put a message out. This is for easter egg type of finds, where the hit is noted, but no message is put out unless the player intentionally presses E blindly, allowing there to be many items that the player can check out in world exploration without having messages just pop up continuously (that is to say, a player can look at anything and press E and often will get back information from items that aren't normal pickups or use items).

The only other significant thing to mention is that the message content comes from the class that was hit. So for example "Press E to fly this craft" would be a public variable embedded in the class that was hit, which can be extracted on hit, like MessageToDisplay=Hit->GetActor()->MessageToDisplay.

I chose to do this in my walking Character class because I didn't want messages popping up when they were driving or flying. It's done in the Tick() function of the Character. This might be too expensive, but I will change that if I run into performance issues.

I based this on a tutorial by Tom Looman called UsableItem. Search on those three words with UE4 and you will find it. His method assumes that all usable items are in a single class, but it's easy to extend so you can discover any type of class.

more ▼

answered Sep 09 '16 at 02:21 PM

avatar image

eagletree
475 26 12 44

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

Hey Suhaib,

for Ego Perspective Games I usually use Line Tracing from the eye position. for 3rd Person Games you could use a Sphere Collider or a Box Collider which is in front of the Player. (The position and scaling depends on the game)

Greetings Cloudy

more ▼

answered Sep 09 '16 at 05:04 PM

avatar image

Cloudy McStrife
465 13 15 38

(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