Download

Player / object interaction

Hi guys just wondering what the best way to go about player and object interaction is.
Example my world is populated with many trees , when the player walks near a tree that he can cut down an option will appear eg ‘chop down tree’.

Now do I simply add a collision sphere/box to the tree and use it as a trigger. But then let’s say I have 1k trees won’t this cause performance problems.

Or the other option is to do a ray cast from the player to see if it hits the tree but then wouldn’t I have to constantly / every tick , cast the ray to see if it hit the tree which again I don’t think is a good idea.

So what are the options or best practices to use??
Thanks

If you go with the line trace method, you could use that line trace for more than just the tree. Reuse the result to check for more things. Or do what I do and have an enum with “None”, “Pickup”, “Physics”, etc. Then have an interface that will have that enum as an output. Use the interface on some stuff in the level that you want to interact with and have it output what kind of interactable it is with the enum. After your line trace, try the interface message on the traced object and switch on enum. You can then use that one line trace for all your interacting needs.
Of course, that means that the way players will be interacting with the world will be by directly looking at what they want.

If you want the collision method, I think that if you use the basic types of collision actors and not per poly stuff, it shouldn’t be too bad. Just turn off tick for all of them, and, if possible, create a custom collision channel and have just your pawn overlap it. That way on overlap won’t trigger when anything and everything enters it.

You’ve confused me now how can you reuse the ray cast ? As soon as the player moves or looks around you would need to recast again? But my question was if I do use ray cast how would I call it?

Or do you just have youres running all the time? I’m only thinking because if I have hundreds of players all ray casting continually won’t that bog the system down?

Hey, maybe my tutorials can help you out, they let you interact with the foliage itself, eliminating the need for triggers or anything special:

Yeah I checked out you’re tutorials and they are very helpfull good job bro.

but in you’re case you have you’re linetrace hooked up to the button ‘f’ what I want is for example say the player is facing forward and there is a tree to his right, the player turns to look at the tree as he lines up to the tree so that the tree is now in front of him I want it to come up with the text description eg ‘Birch Tree’ then as he gets within action distance for the action menu to come up like ‘chop down tree’ ‘forage for food’ etc

So the only possible way I can think of doing this is to either use triggers or to have a line cast continually fireing but I was worried about performance issues especially as it will be multiplayer so potentially multiple trees being interacted with at once. This wouldn’t be just for trees but let’s say an apple was on he ground as I got near the apple or pointed the crosshair at it then the text would say ‘Apple etc’ as I got closer the apple action menu pops up eg ’ examine Apple’ ‘pick up Apple’

Omg I think I’m being stupid isn’t it possible to call a on mouse over or on hover for actors?
So couldn’t I just do like when the mouse cursor/crosshair hovers over the actor then call the line trace??

P.s where did you get thy wheat model ?? I really need one for my game but I can’t find one anywhere lol

I am able to do 5000 line traces in 1 frame with hardly anything of a lag spike (as long as debug draw is off), you’ll be fine doing a line trace each frame, as even 5000 line traces only takes like (.05 to .1) seconds. As for the wheat model, I got it from the Nature Package: https://forums.unrealengine.com/showthread.php?56951-Nature-Package

Thanks for you’re help but I still don’t think its good practice to have It fire constantly
I found this In the documentation
https://docs.unrealengine.com/latest/INT/Resources/ContentExamples/MouseInterface/BlueprintActors/index.html

So what I will do is try and find a way to lock the mouse position so that it is directly over the top of the cross hair then try and use mouse over events.

Eg when the mouse Is over the static tree mesh , fire the line trace and display the name etc . When the cross hair/mouse isn’t over something interactable it will do nothing.

I checked out that thread but I couldn’t find anywhere to actually buy the package for the wheat. Is it the one on the marketplace?

Thanks again

Yes, it is on the marketplace, you’ll need to buy the whole package unfortunately. As for your issue, I’d like to know more about your results and if you can get something working.

ok cheers mate. yeah will let you know how i got on .

Just FYI you will still need to be doing a continuous line trace to check if there is an interactable mesh, otherwise how will you know whats under the mouse?

Did you not check the link there is a mouse over function that can perform actions when it’s over a mesh. Eg when mouse is over static tree mesh "do something "

In their example they are grabbing a sphere and moving it around .
In my case I will simply check when the mouse is over a tree mesh

“OnBeginCursorOver - This is triggered whenever the mouse cursor moves over a specific object. In this case, the sphere Static Mesh, which is one of the Blueprint’s Components.”

Thats the callback event. It is still doing a trace every frame to figure out what is underneath it. So the performance would be the same as doing a trace yourself I would assume, but yeah that does solve your needs but means you have to put in each of the meshes the event rather than in the player controller.

This would mean the player is also able to interact with the object when he is NOT facing it (which would be kinda weird :D)
I see you want to create a menu system like the ones in the dayz/arma games. I guess the line trace solution that was already stated would be the best way to create this. They did the same in dayz.

Yeah I get what you’re saying but the reason I wanted something seperate is because

I want the player to be able to identify an object from a distance so in this case a tree but in my game I may have several different types of tree.

So for instance say the player needs birchwood from a birch tree , he would aim the mouse/ cursor at all the different trees untill he finds the right tree

it would then come up eg 'birch tree" “10 branches” “4logs” “quality 6” etc
So let’s say that is the tree I want I then need to turn it into a dynamic mesh so the player can interact with it. But if I just use the one trace it will not take into account the players actual distance from the tree and if he can interact with it.

So really I need 1 trace from a distance to check he trees but then also check the distance to see if the player is in range but obviously the sight to the tree distance will be higher than the interact distance

Howether if it’s not the tree the player needs I want it to remain a static mesh and only display the stats .

Or do I simply just fire off two traces at the same time . One would be the max view distance and the other the interact distance??

Just pull all of the data on the one trace. Compare and see. You don’t need to run two traces to get the view and the interact, just see if the range is within the interact range.

Line Trace for sight distance, check if the Impact Point is within Interact distance.

When you break the trace struct, you can get the distance between the start and end point.