Trying to make a object collide with itself

I am having trouble making an object slow down and stop when its in range of another copy of itself from a spawn point I made. I have tried to use the following.

Raycast - no lunk
Point inside - Doesn’t seem to work
And ofcourse in collision causes the biggested problem

The only thing that seems to work in a way is the distance between objects. but what happens is every instance of the object stops or slows down within distance of itself.

I have tried to work around this by creating separate copies of the same sprite but the work is too much. I have used the topdown behavior to make the objects move.

BTW its a car links below

Project file

I know there’s multiple ways of doing this, here’s one. I don’t know what your project looks like. I couldn’t think of a way without using a 2nd object. In this case stuck to the front of the cars using the sticker behavior and used as a hitbox.

See it, there are no interactions. I left the 2nd box visible and semi-transparent. I added a counter by each spawn point just to check the randomness.

Project files:

EDIT: There’s an issue with this technique. Sometimes, the cars collide at the same time and become stuck. IDK if it needs a change in code or the size of the hitbox. But… this is a starting point.

Thank you sir you are a legend. I really appreciate it. I have been stuck on this for awhile almost to the point of just making duplicates of the same object and doing a delete control event to make sure there are not two of the same instance on screen. I will try this out and let you know.

I wish you well. I need to do some more testing. The cars can get stuck in each other’s hitboxes. I’m not sure how to avoid that. It might be as simple as adjusting the size of the hit box.

The same technique could be used for a raycast or point is inside.

hmmmmm…I was thinking the same thing. But the point inside doesn’t seem to work for some reason

The problem with raycast and point inside is you need 2 objects bc if you use for each object it only selects the one object, so you can’t test against other object. if you add a 2nd you can use it in the for each*. Also, with raycast you need to set the angle in the direction the car moves and the source of the raycast outside of the car.

Here’s version with point is inside. I shrunk the hitbox and kept it visible for testing. You can move the car point named “Test” to change the point is inside

see it:


Just a little explanation of this:

When you do the point inside, it picks the car that it’s inside but you need the other car. So, you need to pick all of the cars and get the car stuck with the sticker behavior. FYI is stuck to is from the sticker behavior and is in the [Other Action] tab under [stick objects to other]

The section to move again: You need to use the NOT point is inside instead of [inverted] point is inside because the [inverted] point is inside checks against all of the cars. So, since the point isn’t inside all of the cars, it will be true and trigger the action. The NOT point is inside is flips the result. So, if it’s inside a car it inverts it and returns false but if it’s not inside it inverts the false to a true.

Then again, you need to make sure all of the cars are available, so you use pick all again and get the car the object named hitbox is stuck to.

It confuses me sometimes but you need to remember the invert flips the condition while the not inverts the result. It’s subtle but different.

I decided to make a raycast version too since it was almost there.

see it.

I hid the hitbox object and added a shapePainter object to draw the point where the ray detects a car.


Wow Thanks man ! I’ll check it out now.

1 Like


Hey dude thank you for this, it made my life much easier. I just have one more thing to ask. Does it have to be a force or can I use the topdown platformer behavior for the cars, because I want a more realistic stop and start movement and I need to make the car turn corners if needed. would this be possible with your way of event ?

The concept would work but it would need to be reversed. It would be the same triggers. I’m not at my pc maybe later if it’s still an issue.

Simulate the proper directional key when there’s no object and then stop pressing when there’s a vehicle.

1 Like

You see the thing is I have this in my code at the moment and it makes the cars turn depending on the angle of the road.

Does it work?
Slow down if it detects a car.
Speed back up to the max speed if there’s no car.

hi Keith

its not but it is doing thing for some reason

Check the car’s “test” point. It looks like the hitbox object is using the center point. I think that happens if a point doesn’t exist or misspelled. Does the car sprite have a point named “Test” somewhere ahead of it. If the point is on the car then the car doing the testing is detected by the raycast.

Aaaaaaaaarh ok fixed now. Thanks Keith you are a god my friend.

1 Like

now it works correctly.