Keep actor "certain distance" above player?

Hi,

I have some actor spawn points just off screen above my view. They spawn some actors that slowly fall down. I would like these spawn points to always stay above the character just off screen.

How would I controll the “Z” parameter of the spawn points to be "player character Z + (amount)? But constantly changing?

Thanks for any help

Don’t try and keep a spawn point some distance from the player. Why not just do the calculation when you actually want to do the spawn?

The spawn points would need to be in an actor (e.g. BP_SpawnPoints). Then you move the actor on tick with conditional checks before move.

On tick get Capsule Component world location and compare it against the SpawnPoint actors location (distance between the two should suffice). If distance is greater than n → move to current location.

Set actor location w/capsule components world location.


@ClockworkOcean is right about only moving it pre-spawn.
When you need to spawn your actors, compare locations of the two. If you need to move, then move. Then call spawning.

1 Like

Ok, is this something along the lines of what you were meaning?

Pretty much, but for performance you should only move on spawn. Get off of tick.

Tick is bound to your FPS. So if you are playing with 144FPS you’re running that move code 144 times a second. Wastefully inefficient.

Create a custom event for all the code you just posted.
e.g. Move Spawner.

When you need to spawn something call the Move Spawner, then the spawn event.

@Rev0verDrive @ClockworkOcean

Thank you, This is working for me so far. I’ve just go some cleaning up to do on my end.
Wanting to adjust it now to randomly spawn from a wider area but always at around that height above me. I was able to make some target points and reference those with a random array function to randomly spawn from the points I made. Now i’ll try to merge that with this to keep it above me.


1 Like