Is there a limit for force to detect a collision?

I can delete the ball if speed is up to 300 but if it’s higher, collision is not detected.
Any help?

Why are you not using the built-in collision conditions?

The events are run like 60 times a second. The ball is moved a little each time. There’s going to be a point when it moves more than a single unit per frame and it will go from a distance of 1away to a distance of 1 behind on the other side. (5, 3, 1, 1,3, 5)

Edit: If I’m reading your condition correctly it shouldn’t even work since the distance should never be below zero since it starts counting up again after it passes the wall.

If there’s a reason you don’t want to use the collision then you can use ball.X() > wall.X(). (Or < if it’s the other direction)


That’s is just an example. Actually, I want to change the ball direction after it collide in the wall.
I want it goes down, but in the same Y position of the wall.

If you want to create the effect of a ball bouncing off walls then the physics behavior is probably your best choice.

Tutorial for a breakout style game:

Not bouncing. The ball is created at (50,100) and goes to the right using force on X. The wall is at (500,100). When the ball is exatcly at the same position of the wall (500,100), I want the force change to Y the way the ball goes down, but keep the ball.X=500.

Ok. Have you tried the collision condition. Is there a problem with using it?

(Rough code)

Create ball
Add force x=300, y=0 permanent
Set object boolean moving =true

Ball collision with wall
Ball variable moving= true
---- ball variable moving=false
---- ball variable falling =true
----- ball stop the object
----- ball add force x=0 y=300 permanent

I cannot find a way to assign the collision point at (0,0) if I use collision. It only works if force is 300 or less. Force=400, the ball pass through the wall and nothing happens.

Maybe the collision mask needs to be wider. You can also use a hidden sprite that’s wider.

You can also compare the ball.X() to wall.X() and if greater, stop ball, set ball.X() =wall.X() or whatever value and add a new force.

Good luck with that. You won’t be able to get exact positions using a force. And I know you’re rounding, but if it skips a couple of pixels in a frame, then it could miss the spot.

To achieve what you’re after, I’d suggest raytracing a line from the ball out in the direction it’s going and use the wall as the objects to check against. Calculate the distance from the ball to the raytrace detected wall object, work out the time it would take for the ball to get there at the speed you want, and use a positional tween to move the ball.

I’ve tried that but no avail. The problem is the game will have a lot of walls and balls running in all 4 directions, so I need to find a way to simplify the code. The ball 1s 32x32 and wall 64x64.

Wow. It looks so complex, I think I’m going to move the balls like I was doing. By positions X+1, Y+1. It’s way easier! Arthuro said it’s not a good practice because of frame rate, but I guess it’s not gonna be a big issue. Thanks all!

Not really, it’s reasonably straight forward, and far more accurate than what you’re doing. If you need help, I can rustle up an example of how to achieve it.

Ok, but keep in mind it’ll run at different speeds on different devices and the ball won’t move nearly as fast as what you want (400+ pixels per second).

Many thanks for advice!

I’m gonna try it. I like to try and solve. If I get in trouble I ask your help. Thanks in advance!

1 Like

Hi MrMen. I’ve spent a lot o ftime trying to figure out how to do it, following your instructions, but I gave it up. I set up 2 walls, It works on 1st but no way to make it work on 2nd. If you don’t mind to make a simple example, I think it’ll be easier. I’d appreciate that.
Many thanks, and no hurry!

Here’s what it does :


And here are all the events - each commented section is for a specific direction. They’re all very similar, with a few small, but important, differences :

Note that with the raycast, the extra 33 is so that the raycast starts outside of the wall object the ball may be on. Otherwise the wall block the ball is becomes the target of the raycast, and the ball won’t move.

Many thanks! I’ll try to implement that. I was still using force and not tween. Wish me luck!
Have a very nice day!


What am I doing wrong?
My ball stops when it reachs the first “seta4d”, when it should go down.

Ah, one [important] thing I forgot to mention - I changed the origin of my wall and ball sprites to be the at centre of the object. If you do that, then it should all be working. Apologies for the omission.

BTW, your events assume seta4d is 48 pixels in size. I hope this is the correct dimension, otherwise change the 25 to be (object size/2) + 1.

I changed the origin points to the center as well. The ball_mag is 50x50 px and seta4d is 80x80 px. That’s why I added 25 px to the ball x. I tried adding 40 but none of them works. I tried 26 and 41 also.