• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

SOLVED box2d Circle resting on triangle point

Azenris

Member
Hi,

Im using box2d for the first time.

Curious how do I stop a circle collision from resting at the top of a single point. Eg. A circle on triangle

rniVYz4.png

Not sure what code you want. Is this a setup problem?

Ask if you need to see anything. Actually Ill atleast give the properties

ball
density: 1
restitution:0.4
lin damp:0.3
ang damp:0.1
fric:0.35
sensor:false

pointobject
density: 0
restitution:0
lin damp:0
ang damp:0
fric:0
sensor:false

world
xgrav:0
ygrav:15
physics_world_create: 0.1
physics_world_update_iterations:15
physics_world_update_speed:60
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Usually the circle will not rest at a point of a triangle unless aligned flawlessly, so randomizing the initial position by even a slightest amount will cause it to lean over in one or other direction.
 

Tornado

Member
I didn't quite understand the question, but if this is your starting point and you want to move the ball to the left or right (like YellowAfterlife assumed) then you can apply impulse or force to the ball.

For example:
Code:
randomize();
with (ball_instance) {
    var _xforce = choose(-5,5);
    physics_apply_force(x, y, _xforce, 0);
}
This will push the ball randomly to the left or to the right. Change numbers 5 and -5 to your preference if you want less or more force.

Manual:
physics_apply_force
physics_apply_impulse
 
Last edited:

Azenris

Member
Well this is a ball bouncing around and sometimes it boucing in the air and loses its horizontal velocity and end up falling down perfectly. Sometimes landing on the triangle point. It happens way to often to do nothing.

Maybe I will have to add code to the collision event that checks if it has come to a rest and apply and tiny, TINY force. to a random direction (but might look weird)

I don't want it to look like its being pushed, hopefully it will just give the appearence that circles cannot come to a rest on points. and its just rolling off

Will test tomorrow :]
 

Tornado

Member
I can't imagine that it falls that perfectly that often. Maybe your point on the top of the trianlge is not one point (it seems to me like more points).
Try to modify the fixture of the triangle so that you have really one point on the top.

And I think there is nothing wrong if you apply a tiny force.
 
Last edited:

Azenris

Member
I just added some code to the collision to move it.

GML:
if ( abs( phy_speed_x ) < 0.07 and phy_speed_y >= 0 and phy_speed_y < 0.5 )
{
    var _dir = choose( -1, 1 );

    phy_speed_x = 0.2 * _dir;
}
seems to be working for what i need. I'll mark as solved

ty
 

Tornado

Member
Ok, but try to avoid manipulating phy_speed_x and phy_speed_y directly. This interferes which physics engine.
Maybe it is not relevant for your example now, but just keep that in mind.
This is the reason I recommended using physics_apply_force.
 
Top