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.
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.
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.
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
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 NOTpoint 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 NOTpoint 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.
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 ?
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.