Download

How to (Projectiles + Calling and destroying other actors) ?

Hi,

I created a simple tank object (body and turret). I was successful getting it to do the following:
1- W & S keys move the tank forward and back
2- A & D rotates the body of the tank right and left
3- Q & E rotates the turret right and left
4- Space bar fires a projectile spawned at the tip of the turret

I’m stuck getting the projectile to move or destroy a simple static mesh box object.
Here’s how my projectile looks like:
1- It has a projectileMovement component
2- Sphere component with physics enabled (blockAll or overlapAll)
3- static mesh sphere object (no physics)

a- Do I make the hit and destroy decision in the projectile blueprint or should it be done on all objects that are being hit?
b- Should I call ‘Event begin overlap’ or ‘Event Hit’ or call functions on the projectileMovement component or call functions on the Sphere physics compenent?
c- What’s the difference between ‘Event begin overlap’ and ‘Event Hit’?
d- When I call event hit and the call destroy actor and connect hit-otherActor to destroyActor-Target nothing happens. How do I get a reference/pointer to other actors in the scene into my projectile class?
e- Finall, How do I destroy objects when projectiles hit them?

The object I’m hitting is a resized copy of the map_floor box object with physics enabled and set to blockAll.

I don’t fully understand the different physics modes and how they affect actors and interact between each other…Any references/video tutorials on physics?

Attached is an image of the simple setup.

Thanks a lot!

tank.jpg

a. it’s better to do that with in blueprint unless it’s super important(like match win/lose objective)

b.basic rule of thumb, if your projectile bounce off, use Hit, otherwise use overlap.
But you have to make sure our projectile’s collision don’t ignore static mesh(or whatever you want to generate events with).

c. they are just events, but the event output gives you different data to play with.
Hit event lets you have (almost) exact location of collision, you can thus spawn particles for explosions.
Overlap is more tolerable, and cheaper to calculate, but the location is not as precise(if your collision shape is bigger than your projectile mesh, it could seen by others that your projectile do something before it actually hits.
(it’s actually the same for hit if your collision mesh it too big.)

d. it would be better that you do everything else before you destroy your actor being hit(doesn’t matter if it’s projectile or mesh).
if you want to save the instigator(who fires the projectile), when you spawn your projectile you need to expose that variable on spawn so you can connect it with SpawnActorByClass node.

e. call their event let everything destroy itself(with the exception of condition I mentioned in a.), preferably use any damage related events. get familiar with it, will help you down the road.

Thank you PenguinTD! Very helpful points and information.

For (d), I should clarify more…
When I use (Event Hit) and try to connect its (other actor) component to (destroy actor->target), nothing happens.
Shouldn’t the (other actor) component in (Event Hit) reference the object that projectile hit with and by connecting it to the (destroy actor->target) it should destroy the other object?

For (e) How do I call their events within the projectile blueprint? That’s probably tied to (d) above. How do I get a reference/pointer in my projectile BP to other objects in the scene?

Ok, looks like I was using the wrong objects to collide with.
I was using a resized copy of the map floor and no matter what collision setting the I used with that object it wasn’t doing anything. I couldn’t even create a blueprint out of it.
I instead used a box mesh that I created in a 3d application and created a blueprint out of it. Placed it inside a box shape component and set the collision for that shape component to blockAll.
The projectile (Begin overlap) event worked fine and was straight forward. On begin overlap just destroy other actor.

Do I have to create a blueprint with a shape component in order for collision to start working? I couldn’t get the projectile to collide with meshes that are not blueprints