What is the best way to use line trace here?

Hi guys!

It’s my first time developing a game, and my game is about managing stores… (Place items on shelves, interact with boxes, doors, products…)

I have a question about line trace. Currently I have a line trace in my FirstPerson who makes me able to identify basically all the items that I can interact in my game. I have a lot of validations to know what object the player is looking at, in order to allow different ways to interact.

I do these validations using interfaces or tags for example. But, this is the best way to do something like that?

In my screenshot you can see that I have a lot of if-else to validate what is the object that the player is trying to interact… I know, it’s a mess, but I’m trying to organize my code. It’s working by the way, but I don’t know if it’s the correct way and I would like to have the best approach in my context.

I’d appreciate it if you could leave your opinion…

Thank you for your help!

1 Like

If you use an interface correctly, all you need is

Because the interact event can be implemented differently in each kind of actor.

That’s the point of an interface, you don’t need to find out the type of the actor :slight_smile:

There is not such a thing like BEST way :slight_smile: there are always different options. Some are better and some are not LOL.

Here is one that you can try:

get the tags of the traced object and proccess with a function that drives the flow of the objects like this:

image

create a function that takes those tags and compares with a list array of tags and then you can switch by index like this:

tagIndex is a local variable set as -1 by default so it dont run anything if tag not found.
hope it helps!

Cya
Dany