how do you set a specific collision box to be interacted?

well i messed around with it for a good while and just made a new button, used the other box and its tag to print text, exact same problem so its a definite issue with that code you shared

Disagreed. The script is solid and would do in a pinch for something as basic as this. Triple check your components tags.

Also, the suggestion here is valid and one of the few instances where I do not hate enabling input on a non- pawn / controller actor. Seems quite manageable if treated like so.


I can think of a couple more elaborate (and efficient) ways of handling such interaction but we’d need to justify the upfront work first. As in:

  • what else is required?
  • how far do you need to take it?
  • how diverse and numerous will the interactive elements be?

If it’s small game project with 1 car and 1 player, I would set up the tags or enable input when needed and forgot this existed.

1 Like

i have checked them many times, regarding the other suggestion i dont even really know what hes doing what enable and disable input is achieving and what would need to be done with that, the tags do not work ive pretty much reverted my code at this point. i just wanted to go to the back of the car, press a button and print a string and i cant even do that.

For a more agnostic, modular and scalable system, consider the following:

The Interaction Base

  • an actor with a collision volume:

  • it has the interface implemented
  • and a single instance editable variable so you can edit the size of the collider
  • the player will interact with this actor (its children, actually), not with the car

The Interaction Children

image

They inherit the interface and can:

These are the entities the player interacts with. Do note that since these are full actors, things open up here - perhaps the trunk is where we handle the inventory, something the car may not even need to know about…


The Ride:

  • the car is an actor and has a bunch of Child Actor Components representing the interactive areas of the car:

  • the CACs instantiate the appropriate child of the Interaction Base
  • you can edit the box extent here

The next step would be to set up comms between the interaction actors and the actor that owns them. Event dispatchers would work as well as an interface.


The Player

Well, the player does not and should not care about any of the above. They will be super busy doing more important stuff.


In short: the car actor has components that create other actors and we talk to those actors instead. They can then talk to the car actor that owns them, if at all needed. I wouldn’t do any of this if all I needed was to:

go to the back of the car, press a button and print a string

But if needed to set up a world where the player can interact with a bunch of unique objects, I would absolutely experiment with going this route. If the player runs into an abandoned house full of lootable containers, attach a CAC_LootBox to a world actor.


Project link:

1 Like

if there are multiple cars next to each other, you might find yourself touching one car’s trunk and another car’s door at the same time. I think the solution needs to take into account which trigger the character is facing most, using dot product.

if you loop through all the overlapping collision triggers and use the dot product of the character’s rotation’s forward vector and a normalized vector of each triggers location minus the character’s location, it will give you a score conveying which trigger is more in front of the character, and only the highest score should get the interaction.

also, you could do all of this with 1 actor and 1 box collision, if you use dot product to check where the player is standing relative to the cars forward vector and right vector. if the comparison with the cars forward vector is nearly 1, you can pop the hood, if its nearly -1 you can pop the trunk, if the comparison with the right vector is nearly 1, its the right door, if its nearly -1, its the left door, if they are both negative, you are at the back left tire, etc… with just 1 box, you could check which door or trunk or wheel you are nearest, but you also need to check which you are facing most, so you don’t pop one cars trunk while entering another car.

CarDoorDetection

1 Like

oh wow thats insane, i dont suppose youd be able to share the project for this so i can take a better look

The project is no longer available, but here is what it looked like:

this really helped me a lot thank you

1 Like