Fixed joint is affected by centrifugal forces

Hello, I am very new to the engine, so I would like to apologize if I missed something. Tried to search information, but so few posts are there about physics joints.

I am trying to make a ‘wheel of fortune’ type game and made the wheel, its big collision object(dynamic) and the axis(static) it rotates to without a hitch ( connected by hinge joint). Had some issues with the pin that should collide with the pegs on the wheel, but managed to solve it with 2 static objects with each side of it and connected to the pin with spring joints and it behaves good.

Thing is when I started to populate the wheel with its peg collision objects (dynamic) and connecting them with fixed joints to the wheel collision object there is a problem. When I apply force to rotate the wheel and when that force goes beyond certain threshold(not much, mind you) the peg starts to move away from the wheel as affected from centrifugal forces. I did specify in the joint that the max_length of the rope is 0 with no change.

First I tried to add the pegs as different shapes to the main collision object of the wheel, but the engine said that there is a maximum of 16 shapes(or was it collision objects) and I didn’t see that limit anywhere in the docs( I need something between 24-32 at the moment). Is there a way to make the pegs stick to the wheel when it rotates as different collision objects or even game objects, because I would prefer to create them in the code in case in the future I change the sectors of the wheel or add more pegs for each sector, or perhaps change some setting to enable more shapes to the prime collision object?

Let me know if that description is not enough and I will make screenshots or video. Thanks in advance.

What if the pegs are kinematic (or even trigger) and parented to the wheel. They would still inherit the rotation of the wheel but they would not be affected by forces, gravity etc.

I tried this, but then I don’t know how to make the pin collide with them, at least visually.

Hmm, I thought that should work

Thanks for your input. It kinda does, I mean if the speed of the wheel is slow enough the kinematic peg makes the pin to move, but just very little, not like a dynamic object. If it has higher speed in debug mode just register the collision by changing the color of the collision object and that’s it. Is there a way to make it more visible and also to do this at any speed? I will add a function to apply little negative force at each contact, but I am more concerned with the visuals, because now they are not realistic at all.

PS: Is it possible this thing with using fixed pin joint and still the collision object be affected by centrifugal forces be a bug? I tried similar simulation in a different engine - godot and there wasn’t such behavior.

I think I found where the issue lies. I did change the physics scale from 1, to 0.01( which is still too much) and now it behaves almost what I want it to do. I guess when scale is 1 pixel = 1 meter 600 pixel wheel means 600 meters in diameter and perhaps it generates its own gravity (lol) even if I did specify no gravity for the project. Still at some speeds some of the collisions with the pin are not making it swing as it should, I guess it is perhaps to do with friction and restitution settings. I will continue to experiment and will update this, because there are no examples of this kind of behavior, at least I didn’t find any.

1 Like

I know it has been a long time, but I was busy with different things and this “global shit” that just came upon us didn’t help much. Looks like scaling solved most of the issues.

My tests were using only one peg or a few. I guess when the speed of the wheel moves beyond certain threshold collisions between the arrow(pin) and the pegs(I see them as nails on the wheel and the word pin is much more suitable for me, but I read somewhere that they are called pegs) just skips, only color of the collision object of the arrow flashes and sometimes not even this. I guess physics engine doesn’t know what to do when stuff like this happens. Its still 2d, but I guess it tries to match Z dimensions and makes em slide one over the other, because of the huge momentum.

Last few days I got some time to work on this and managed to make pegs generate from factory and attach em using fixed joints. Took me some time(more than I am willing to admit lol) to remember trigonometry and then not to, because I was using my algorithm to calculate coords of the pegs. When angle went > 180 degrees things broke and made me realize we got functions available to calculate those things! I am new to game engines and it shows lol. Then It took me some time to find out how the hell to address collision object inside the game object that was generated from factory. Found the answer in the forum, but I think you should add this in the factory.create manual, because I think its where it belongs! Would be of huge help to noobs like me!

Now I got dynamic pegs generation from a factory and a slight change of the number of them and they will be positioned automatically on the wheel and create more sectors or perhaps get more pegs per sector - 2 on each ends and one 1 the middle for example.

function generate_pin_coords(wheel_position, wheel_radius, pin_count)
	local pin_angle_add = (2 * math.pi) / pin_count
	local pin_angle = 0
	local pin_coords = {}

	for i = 1, pin_count do
		pin_angle = pin_angle + pin_angle_add
		-- at start wheel is positioned with the arrow(pin) in the middle of its first sector, so then first pin should be positioned with half the angle
		if i == 1 then pin_angle = pin_angle_add / 2 end
		local pin_position = vmath.vector3(0, 0, 0)
		-- get arc displacement by the angle(360/pin_count) and position by the wheel position and radius(wheel_radius)

		pin_position.x = wheel_position.x + math.sin(pin_angle) * wheel_radius
		pin_position.y = wheel_position.y + math.cos(pin_angle) * wheel_radius

		pin_coords[i] = pin_position
	end
	return pin_coords
end
-- Create all the pins from pin_factory component
local wheel_radius = go.get("#sprite", "size").x / 2
local pin_coords = generate_pin_coords(go.get(".", "position"), wheel_radius, pin_count)
local pin_count = 0
for key, value in pairs(pin_coords) do
	pin_count = pin_count + 1
	local pin_obj = factory.create("pin#factory", value, nil)
	local joint_position = vmath.vector3(0, 0, 0)
	joint_position = go.get_position(".") - go.get_position(pin_obj)
	-- create the physics fixed joints at their respective positions
	physics.create_joint(physics.JOINT_TYPE_FIXED, "#collisionobject", "pin-" .. pin_count, joint_position, msg.url(nil, pin_obj, "collisionobject"), vmath.vector3(0, 0, 0))
end

Hope this helps someone :slight_smile:

BTW I would kill for word_wrap in the editor! So basic, but needed feature! Cheers and keep the good work guys!

Good point. I’ve added a new section to the Factory manual:

2 Likes