• Register
Forum Thread
  Posts  
How to get signals upon vehicle collision in UE4? (Forums : Coding & Scripting : How to get signals upon vehicle collision in UE4?) Locked
Thread Options
Nov 23 2016 Anchor

Could someone help me out with this, It would be greatly appreciated if someone would link some tutorial on how to get signal upon vehicle collision to the user. For e.g: display on side of screen message like "Hit Taken" or "Critical Hit" "Medium Hit" or "minor hit" some thing like that?

Nightshade
Nightshade Unemployed 3D artist
Nov 26 2016 Anchor

I haven't worked in UDK for ages - and never with logic.
But basically you need to setup collision meshes first, tied to the various objects in your environment (the vehicle, the road/path you travel along, breakable objects, non-breakable objects, etc). You then perform collision-detection in your code between the vehicle and the things that should trigger the effect on the HUD. You then either pass a message to the manager dealing with the HUD (like: "hey, vehicle just collided with a collision-mesh that belongs to the non-destructable class) or you setup some sort of event-listening system - I'm unsure what but those are two common ways of doing things like this.

Google some on UDK collision detection and I'm sure you'll find plenty of info.

Edited by: Nightshade

--

   - My portfolio
“There he goes. One of God's own prototypes. Some kind of high powered mutant never even considered for mass production. Too weird to live, and too rare to die.” Hunter S. Thompson

Nov 30 2016 Anchor

Blueprints

Basically, you just make an Event Hit (for a physics collision) or Event Actor Begin Overlap (for a trigger overlap) and do whatever you want to respond to those. There is also an Event Actor End Overlap as well if you care about that.

C++

The C++ implementation is virtually the same; the hooks mirror what's available in Blueprints.

Header:

// For hits (physical objects)
UFUNCTION()
void OnHit(UPrimitiveComponent * _hitComponent, AActor * _otherActor, UPrimitiveComponent * _primitiveComponent, FVector _normalImpulse, const FHitResult & _hit);

OR

// For overlap (triggers)
UFUNCTION() 
void OnOverlapBegin(UPrimitiveComponent * _overlappedComponent, AActor * _otherActor, UPrimitiveComponent * _otherComp, int32 _otherBodyIndex, bool _bFromSweep, const FHitResult & _hitResult);

Constructor:

// For hits (physical objects)
m_CollisionPrimitive->OnComponentHit.AddDynamic(this, &AYourActor::OnHit);

OR

// For overlap (triggers)
m_CollisionPrimitive->BodyInstance.SetCollisionProfileName("OverlapAll"); // If you don't do this, you'll need to set this up somewhere else
m_CollisionPrimitive->bGenerateOverlapEvents = true; // Do this or Overlap events never get generated
m_CollisionPrimitive->OnComponentBeginOverlap.AddDynamic(this, &AYourActor::OnOverlapBegin);
// NOTE: There is also an OnComponentEndOverlap that you can use if desired; the setup is just the same as OnOverlapBegin()

Definition:

// For hits (physical objects)
void AYourActor::OnHit(UPrimitiveComponent * _hitComponent, AActor * _otherActor, UPrimitiveComponent * _primitiveComponent, FVector _normalImpulse, const FHitResult & _hit) {
     // React to collision
}

OR

// For overlap (triggers)
void AYourActor::OnOverlapBegin(UPrimitiveComponent * _overlappedComponent, AActor * _otherActor,  UPrimitiveComponent * _otherComp, int32 _otherBodyIndex, bool _bFromSweep, const FHitResult & _hitResult) {
     // React to trigger being entered
}



Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.