Change actor velocity at spawn, bounce/collision glitch? [SOLVED]
heatblast77
Member Posts: 4
Hi,
I have a ball actor bouncing around the screen. I don't know the best way but I have set 4 actors around the 4 edges of the screen. The thing is I want to spawn balls which move with a random velocity:
if self.justcreated = True
change velocity to random...
After 0.2s
change self.justcreated = False
This works, however SOMETIMES the balls don't bounce off the walls but stick to them and slide
I think the code above is the issue as the balls bounce normally if I just set their velocity inside the actor settings.
Any tips on how to make the ball move at a random velocity once created or is this a glitch?
Thanks!!
Comments
I think I found the issue: If the ball is moving too slow when it hits the wall or when it hits at a weird angle, it does not bounce but slides along it, any help on this?
Set friction to 0 in both, the ball and wall actors.
Mental Donkey Games
Website - Facebook - Twitter
You don't really need any of these rules, timers or attributes as they're not actually doing anything, for example why check - on a newly created actor - whether it is newly created, as the result will always be true. And why then change this attribute to false with a timer (or change it to false at all) ?
I'd dump all that stuff and just have a single 'change velocity to random' behaviour,
I set the friction to 0 for the actors, but the issue still occurs...I think it's something to do with the collide action, This only seems to happen when the ball travels slowly, at high speeds it bounces normally
EDIT: Also seems to happen when the ball strikes the wall at a close to parallel angle
If a 'ball' gets stuck you can break it out of being stuck by forcing its X or Y velocity to change. In the attached demo the ball starts out stuck and will break out after 5 seconds.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
You could also add a little 'noise' into the physics system by adding a small (very small) random angle offset into each collision.
True.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
I always thought that would be a useful attribute within the physics options, alongside friction, bounce, density and so on, you would have 'noise' where you would introduce a fractional amount of randomness . . . for example if you spawn a ball (with a circular collision shape) that falls down to the ground, then spawn a second ball from the same location (set to collide with the first ball) - it will land neatly on the top of the first ball, even after bouncing for a while, whereas in the real world things are a bit noisier, factors like the quality of the surface (even with a smooth ball), air resistance, wind, and so on, will all conspire to have the second ball bounce off at a very slight angle and end up on the floor rather than neatly settle on the top of the first ball . . . .
But like I say even without a built in noise attribute you can add it in yourself.
Thanks for your ideas, I have used accelerate towards middle of screen, as it can apply to the ball getting stuck in any part of the screen