Since I’m working on car game project for my university…I’d like to know how do get a vehicle’s health regenerated by standing completely idle at specific location or point?
You can do it in multiple ways, it depends on where you want to have that logic.
In general this should work, although this only works with 1 Car if you want to to work with multiple cars you’d have to do some extra logic and checks in the TriggerBoxBP.
TriggerBoxBP: Screenshot - 42a6f4d0d84a81df6d62b1cd68218203 - Gyazo
CarBP: Screenshot - 370af5a38895b90de2175d6b99859baa - Gyazo
Not sure if this would work in instances where the car is already in the box but is damaged. But this should put you in the right direction.
Lovely…so if I apply this 2 or 3 places…that one car will regenerate its in one place and the other car at another location…do you this way they’ll both regenerate health at the same time?
It should only regenerate when a car is in the volume, and you just place these volumes in the world where you want them.
So you also have to add a OnEndOverlap event that triggers a Stop adding health event on the Car. So it stops when the car is outside of the volume and not just when it is at full health.
This is a basic set up there are a bunch of other things you have to make sure that happen or don’t happen. But this should give you a good starting point.
Hmm…can you send me a screenshot of blueprint with OnEndOverlap?
Basically create an event on the Car that’s called like “StopAddHealth”
When that is executed you:
- clear and invalidate the timer handle
On the Triggerbox you create an OnComponentEndOverlap then you:
- Get the “Current Car In Volume” and call the “StopAddHealth” event. That should do it.
I understand…Thank you for that but a screenshot of the blueprint will really helpful for 1st time Unreal Engine user like me…
I understand but for first time Unreal Engine user like me…it will be helpful if you can send me screenshot of the blueprint.
Well this is a very good opportunity to learn. Try and figure it out based on what I have said and make a screenshot when you think you have it or when you can’t figure it out and add it here. Then I’ll give you some feedback.
Exactly in the end we all here to learn
below is an example of how this could be done. the example is somewhat like what others have posted but theres a few differences as well. for instance the method used will work for multiple cars and makes use of the built in damage handling system of the engine.
to begin we start with a overlap event to start the script, i chose a overlap event to make it more performant (by tuning parts off when not needed) but you could have the script run all the time if you wanted and use on begin play instead. ok so on begin overlap we check if the overlapping actor is a car, if so then we see if the timer is already running. if the timer is running then we dont need to do anything, if the timer is not running then we set the timer event (repairCar) and set the timer variable.
the timer event RepairCar is the main bulk of your questions answer. here we see if there is any cars in the volume, if there is cars then we apply damage to each car. in this case i apply negative damage so as to heal the car, you could also use direct functions to affect a car health variable if wanted(cast to class → get health-> decrement->set health). if theres no cars overlapping i have it setup to turn off the timer and invalidate the variable.
This system may require further testing but the theory is sound and the quick testing i did worked.