Box2D magic body connection

General discussion about Box2D tutorials
Post Reply
hardcoremore
Posts: 1
Joined: Thu May 10, 2018 7:13 am

Box2D magic body connection

Post by hardcoremore »

Hi,


Does anybody have idea how yo model this platform character with Box2D.

This video shows exactly what I would like to implement for my game platform character:

https://youtu.be/K8fvfh6Es_8

But I really do not understand how it is achieved. There are two things that I do not understand:

1) How are circle body and box body connected so that circle can rotate freely while box is “attached” to it. I know I can add revolute joint to the circle but how to connect box to it. If I connect it with weld joint than box will rotate as well. If I disable rotation to the box and connect them with weld joint then nothing will rotate. If I connect them with distance joint then box will rotate around circle body.

2) How are bullets implemented in this video? Are bullets kinematic or dynamic bodies? If bullets are kinematic then how do they collide with static bodies? If bullets are dynamic then how do they go strait without gravity affecting them.

Many thanks,

Caslav
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Box2D magic body connection

Post by iforce2d »

Looks like a simple revolute joint.
http://www.iforce2d.net/b2dtut/joints-revolute

The box is set to be a fixed rotation body.
bodyDef.fixedRotation = true;

The bullets are probably dynamic bodies with gravity scale of zero.
bodyDef.gravityScale = 0;

http://www.iforce2d.net/b2dtut/custom-gravity

I think maybe you just need to read the Box2D manual before going any further :)
http://box2d.org/documentation.html
Post Reply