How to prevent two objects from touching each other?

Is there a way to stop two objects from touching each other without using physics?
like if you could set a min distance between objects.

Hey @margonvinther!

So… Do you mean every object across the entire project? What would be the purpose there? If that is the intention, can you describe the context here? There may be a better way to get where you’re going- I don’t think you can set a minimum distance.

What you CAN do though, is you can have multiple colliders of differing channels for your game. You can make an additional collision channel- say, “personal space”, right(project settings, search “Collision”, add channel)? Then give every object an additional collision, set it to “personal space” and have it ONLY BLOCK “personal space” and ignore all else. :slight_smile:

I have two homing projectiles with bounce, (which you must have), which flies after the player, but I don’t want them to bounce when they hit each other. (the projectiles)

But I can’t find a solution for it.

Hm. My simplest suggestion would be to make them not collide. But- are you familiar with Elden Ring? The disciple of rot enemies have a many-homing-projectile spell that shoots upwards in a fan, and THEN come towards the player- and they will overlap, but the idea is for the player to know visibly that many missiles are coming at the same time. So even AAA games have a hard time with this. The solution is usually multiple separated arcs/spawn points, or delaying the shots- like say, a flurry of missiles in a space game, they usually fire one after the other with a short delay, because if they fire all at once they’ll overlap.

As far as not wanting them to collide with each other- you will want to make a separate collision channel so the projectiles have their own interaction set. Project settings → Search Bar-> collision should get you there. You can also set the defaults there. Make sure afterwards to give your projectiles that collision channel, and they ignore others using the projectile profile, but otherwise everything else can be what you want. Obviously, something like block Static and Pawn, ignore Camera, visibility etc. :slight_smile:

The problem is that I use the projectiles as enemies, I’m not good enough to make an enemy ai :sob: so the projectiles are the only things that give me what I want when it comes to movement.

Is there no way to determine what they should bounce off or not bounce off?

Not unless you plan on writing an entirely new projectile movement component from scratch with C++ :frowning: which I do NOT recommend.

Maybe go find a way to actually turn these into actors? The pawn movement component is much more useful in this case, and you can use the AICrowdDetour type to make them avoid each other!

Something this simple wouldn’t require behavior trees, either. They’d be pretty basic. Just simpleAIMoveto with an input of:
GetPlayerCharacter ->GetLocation for your goal vector!

Maybe look into a few tutorials for that? An hour or two and you should have that down!

I’ve have looked into it a bit, but It doesn’t seem to give me what I’m looking for, unfortunately.

Well, what is it that you are looking for? The thing is, you have to spread your learning a bit, you can’t expect there to be an exact tutorial for the exact thing you’re looking for. :stuck_out_tongue:

You can’t rely on projectiles as enemies, plain and simple. Unless you are okay with them overlapping. There are tools in the engine to get what it is you want- you have to learn the surrounding principles and then piece together the end result from your knowledge base.

So you want enemies that spawn, then home in on the player, correct? Are these in 3D space? Can they fly? Are they ground-bound(typically what is taught in tutorials)? What is it that you are trying to create, and what is barring you from using pawns? Because if you want pathing to avoid other things… you’re going to need an AI controller of some sort and you can’t put that on a projectile.

Those enemies are what I trying to make, and I’m so close. All I need is that they don’t bounce off each other.

AHHHHHH okay! I talked about this with you before- and given more thought and video showcasing what they’re doing- I think I can help you out a little more here.

They don’t bounce. The skulls don’t bounce! At all. Off of anything! It’s all just blocking. So don’t have them simulate physics, because they don’t bounce.

So what is happening is they have a tall collision capsule, ok… so you’ll want the projectile’s collision to be capsule. It’s all illusion. They are moving around with the entire thing at the same height. But what makes the illusion happen is most likely:

Static mesh component is given the command to loop a curving up and down motion, NOT the entire projectile. If you look very VERY closely, none of the skulls are directly above or below each other! So the illusion is that the projectiles are moving up and down when really… the projectile is more like a pillar! They collide with each other. You just have to turn off all bouncing! They don’t bounce on the ground at all. So they need to block projectile, and just not destroy themselves on hit UNLESS it is a player’s projectile OR the player themselves!

Maybe that’s the case, but if I turn off bouncing, they just stop when they collide.

Try locking the Z position in any movement you do! Keep them hovering a bit off the ground. Or just have them ignore Static in the overall collider, but have the skull block static.

The key here is going to be that the up and down movement of the skull is NOT your projectile- the collider that’s locked in Z position is. Just make sure it’s not colliding with the ground on spawn.

The skulls aren’t bouncing, they’re “woo-woo ghost” floating.

You need:
to put a “LookAt” node on tick for ONLY the static mesh, not “self.”

A timeline with a float value in it started a second or so after begin play (use a delay node) with a low value to start and high value key in the middle, and a low one at the end matching the starting value, and outputting into a “SetComponentLocation”. When the timeline is “Completed”, have that run to “Play from start” with a delay node in between of .00001.

In the timeline you can set curves so it spends more time at the top or bottom or in between, whatever you’d like :smiley:


this is what I used to get the same effect, does it has to be done the other way?

Hmm… if we rework a few things, that could work.

Keep this the way it is.

Make the Capsule collision something very very tall. Like say, 500 units (5 meters).

Make the capsule collision IGNORE static, so it can go through the ground, while making the static mesh collision BLOCK Static so it cannot go through the ground. At the same time, make them both block dynamic? as well. Whatever your projectile is set to be. The problem here is there is nothing keeping the projectile from going too high or too low.

The fight you showed me was kind of engineered for this, I’d wager. No walls. Level floor. So you could program a set, guaranteed bottom and top- which is why I suggested the other method.

Make sure the collider locks the Y and X axis, it should ONLY rotate Z. Going for tall pillars so they can’t overlap, that stay straight up and down.

I think it goes without saying here but- make your collider visible while testing all of this, to make sure all is going as planned.

I got a stupid idea, I use another Projectile Movement Component to negative homing the projectiles, and it kind of works :smile:

Hey, if it works, that’s great- I don’t know what that means but I’ll take it!

Just try to keep this stuff in mind for the future! Never know what you’ll need going further into things!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.