i am really struggling with following issue and cant figure out a good solution:
I have a vehicle blueprint class and want to implement a crash between two vehicles of the same class.
I am using the “OnComponent Hit Event”(Maybe thats already the problem?).
My Problem is, that this event fires multiple times if a car hits another car, but i want it to happen only ONCE…
Relevant extract of my Blueprint (i might not need the branch but just to be sure):
“Hit Vehicle Vehicle” is a function that changes some stuff like velocity of the other car… this function should be executed only once after this event!
Example of what should be possible and happen with 3 cars: A, B and C
A drives slow torwards B and B doesnt move.
A hits B => “Hit Vehicle Vehicle” fires once in both cars, A and B are next to each other right now nothing special happens here because A was very slow.
Right after that C drives with fullspeed into A
C hits A => “Hit Vehicle Vehicle” fires once in C and A, A is still right next to B
A hits B with power of C => “Hit Vehicle Vehicle” fires once in A and B
Picture for my example:
Right now the “OnComponent Hit” would be fired very often in each car… if cars only touch eachother with very low veloctiy(like A and B in my example) the event still fires very often until they really dont move … and the cars are doing strange things because of that. I dont want to use delays or something like that… i dont think thats a good solution… or is it usual to do that? Did i miss something? I really hope you can help me!! Thank you!
Ty for answering, this one helps ! But its not the solution… if 2 cars would crash into another car at the same time this one wouldnt work properly… i would need a “DoOnce” for every other vehicle? and how can i tell him when to reset the the “DoOnce” node without a delay? i want to be able to hit another car multiple times after iam not touching it anymore…
Ty for answering, but i think it doesnt solve my problem… same problem as i have with “DoOnce”… i tryed different stuff but its hard to tell when a hit has ended… my problem in short: iam a car, a car hits me(here i DoOnce) => block all hits of this car until it doesnt touch me anymore…(Here i would need to Reset DoOnce) and its possible that two cars are touching me at the same time… i would need something like “OnComponent Hit Begin” and “OnComponent Hit End” then it would be no problem… i hope it’s understandable
I think there are a few things I would do here. I would first check to make sure the collision presets on your vehicles are very precise (using something a box won’t work; make sure you’re using something like auto convex collision). A method of telling it after every collision is to create a variable right there called Hit or something and the set the value to true before the HitVehicleVehicle event and then set again to false after the HitVehicleVehicle event. Then use a bool to reset the DoOnce node so that it does HitVehicleVehicle once and then resets it. I’m not sure how everything else is set up so it’s hard to say. Also may I ask what are you trying to do because wouldn’t UE4 physics just take care of there collisions for you?
Oh that’s a idea that could work out! But i will need a array with “MyCar”-References i guess… because it should be possible that multiple players hit one car. Before HitVehicleVehicle i will add the other car and after that i will delete it from the array. And i have no DoOnce Node anymore, instead i have a branch with condition: MyCarArray contains Car that crashes me(other Car) right now? So that’s my idea, thank’s for this hint a lot! I will test it later today.
I am already using auto convex collision for my car. To your last Question: That’s right! But is there a variable(let’s call it “X”) or something that allows me to dynamically change the way(Power/Velocity) a vehicle flyes away after a hit? I want to be able to increase(depending on the other cars velocity) or decrease(using heal potion or smthn) the value of such a variable (i made my own variable and try to accomplish this “manually”).
Very low value of X and Hit Event=> Car doesnt really fly away.
High value of X and Hit Event=> Car flyes away a much longer distance
This variable shouldn’t change anything else of the car (like handling or acceIeration). I might have missed something! I hope my english is not confusing much.
I have to “Add Component: Collision”(in Viewport of my Blueprint) that is slightly bigger then my mesh collision. In my case a Box Collision does fine. I called it “OverlapableComponent”(see EventGraph). After that i added a new Object Channel “VehicleOverlap”(Edit → Project Settings).
Now i set the Object Type of my newly added Collision Box to “VehicleOverlap”. In my case the Box should only overlap with other “VehicleOverlap”-Objects. If you dont want to accomplish this, you might not need a new ObjectChannel.
Now two or more cars can hit one car at the same time and the HitVehicleVehicle function is only called once each time a crash happens. You might not need the BeginOverlap Event. I needed it because i had to get the velocity of my car before the OnHit Event happens. EndOverlap Event resets the possibilty to crash a car again. If someone needs help, i am always open for questions.