Hitting Objects & Actors
v1.0
Actors Getting Hit
The original Projectile Factory demo had DemoTarget objects with a ProjectileDemoActorGotHitReaction script. This script does one thing with code: make the material flash pink. We can use Juicy Actions to do this and more.
Instead, we can use ProjectileDemoActorActions, which will subscribe to the GotHit event on the ProjectileDemoActor, same as the original, but instead of a boiler plate reaction, we'll use an ActionExecutor to drive the response β something far more customizable, quick, and easily changed later.
To recreate the original effect, we can use the ColorChangeAction, and set it to flash pink for 0.5 seconds, with a fade via AnimationCurve.
Objects Getting Hit
The spheres and cubes in the scene can be juicy as well. However, Projectile Factory projectiles have many ways of causing a collision, and in many cases, they handle all the behavior effects directly.
In this demo, we want our spheres and cubes to perform actions when they get hit by projectiles.
Each of these obejcts has an ActionOnPhysicsEvent component, which handles both triggers and collisions β essentially it's a combination of ActionOnTrigger and ActionOnCollision. That takes care of many projectile behaviors, but some don't perform a phyics event.
We will make use of the IProjectileFactoryCollisionReceiver interface. Check the docs here for more complete details.
The custom script ProjectileFactoryColliionHandler connects with the ActionOnPhysicsEvent component and triggers the OnEnterActions without requiring a physics event.
It is possible to write a custom handler that works with your custom actions and utilizes the ProjectileCollisionMessage data that is passed to the interface. In this example, we pass in a null collider since not all projectiles of this nature have a collider, but you can make use of the data if you'd like.
See the docs for full details on this struct.
Last updated