UCC events (firing, weapon switch, etc.)

bluebird

Member
Hi,

I'm newbie here and learning UCC. I have configured third person controller with assault rifle & sniper rifle with help of your tutorial videos.
now, I need help with collision detection while firing. (I prefered hitscan instead of actual firing of bullet objects)

Can you explain how to use all events in my project? what is correct way to use these events?(general flow for use of UCC events)

for example I want to check, on which object I'm firing with assault rifle??

I found event 'OnHitscanImpactEvent' under ShootableWeapon.cs script
but I'm not sure how to use it correctly. where should I put my custom logic? (I want to detect whether I hit to ground/enemy head/enemy body etc..)

Another confusion with OnHitscanImpactEvent() & OnImpact(). What's the difference between them?
I found OnHitscanImpactEvent() inside ShootableWeapon.cs but didn't find it inside documentation. In documentation, I found OnImpact() and not OnHitscanImpactEvent().

Thanks
 

Attachments

  • 2.PNG
    2.PNG
    28 KB · Views: 47
This page gives a pretty good overview of the event system:


Using the event system the OnHitscanImpactEvent is a Unity event so you can use that with:


OnObjectImpact is the name of the event that is sent, OnHitscanImpactEvent is the name of the field that is exposed to the inspector.
 
Hi,

Thanks Justin, for links.

Should I need to add this script on every object that I want to detect??
https://opsive.com/support/document...roller/items/actions/usable/shootable-weapon/

I attached this script to ground (plane), it executed successfully.
like that, suppose I want to detect whether bullet hit to ground/enemy head/enemy body/explosive barrel etc..

should I need to add this script on every receiver game object?? suppose there are 25 objects or may be more??
So is there other simple way to achieve this (by following standard code pattern)?

Code:
using UnityEngine;
using Opsive.UltimateCharacterController.Events;

public class MyObject : MonoBehaviour
{
 
    public void Awake()
    {
        EventHandler.RegisterEvent<float, Vector3, Vector3, GameObject, Collider>(gameObject, "OnObjectImpact", OnImpact);
    }
  
    private void OnImpact(float amount, Vector3 position, Vector3 forceDirection, GameObject attacker, Collider hitCollider)
    {
        Debug.Log(name + " impacted by " + attacker + " on collider " + hitCollider + ".");
    }

    public void OnDestroy()
    {
        EventHandler.UnregisterEvent<float, Vector3, Vector3, GameObject, Collider>(gameObject, "OnObjectImpact", OnImpact);
    }
}
 
Right now you do need to listen for the event on every object that you are interested in - there isn't a generic impact sent to the character for when it impacts any object. I haven't heard of this use case for listening for every object - what are you trying to accomplish?
 
I think, you just didn't get my point..

I want to check, where the firing bullets hit.. so I can put custom code logic (just like unity provide Physics.Raycast() so we get hit object which provide all info regarding where the ray hit, and according to it we can spawn a ragdoll at hit point or may be instantiate blood particles at hit point)

I'm interested in game objects like enemy's body, enemy's head, props like explosive barrels.
So if I'm not wrong, I must need to put your code on above 3 game objects. Am I right?
 
That's correct. There isn't a general event that is sent to the character that indicates where the weapon hit.
 
Hey y'all!

Do you need to implement custom code for impact hits? If what you're trying to do is spawn stuff at a hit point or apply damage modifiers to colliders, there are tools already built in. Apologies if I'm misunderstanding, but I'm gonna' shoot my mouth off, regardless =)

This tool has a fantastic surface effect system:
Surface System
... for doing just that in a whole lotta' different configurations. The setup's a little complex, and does still require a component (SurfaceIdentifier?) on each object, but it's possible to select multiple objects, put the component on all of 'em at once and set what surface they all are. Then the ShootableWeapon component on your weapon will send the ImpactType to the SurfaceIdentifier triggering whatever manner of SurfaceEffects you'd like. For example: your weapon fires a bullet (ImpactType=Bullet) that hits a concrete barrier (SurfaceIdentifier=Concrete) and triggers some cool concrete chunks and a puff of smoke and maybe a decal or something (SurfaceEffect).

Additionally, there's the Health component:
Health
... that'll take care of destroying and/or damaging objects in a lotta' different configurations. Additionally, each object with a Health component can specify multiple Colliders at different damage levels (like headshots).
 
Top