Attaching a weigh on a rigidbody

Hey I have this rigidBody(Black triangle) that flies and it spins, but I want one edge of it to always look at the bottom so I thought if I could like put a weigh(red triangle) on that side it would do that, but I don’t know how I can do that help, please

I asked the same question before but nobody answered so I repost with a different style

@slackmoehrle help please

why not just set fixedRotation = true (or allowRotation = false)

because i need it to spin

bende türküm bu arada :slight_smile:

1 Like

süper! Basarilar! :slight_smile:

I never used physics with cocos creator… but in cocos2dx and box2d I would do this by adding multiple fixtures to the body… the red triangle (fixture) with more weight than the other ones. :+1:

1 Like

Türkiye güzel bir ülke!

Ok not sure on Cocos Creator. Can you tell me what this: want one edge of it to always look at the bottom means? I don’t follow.
@Big_Bear might know.

2 Likes

Did you means that you want a corner always at the bottom no matter how you rotate the triangle physical.
if that is your means,you can change the mass center of the triangle to realize it.
change the center of mass like this, and use a downward gravity.
image

you can customize engine,used the box2d api “SetMassData” to set the center.like

            var massData = this._b2Body.GetMassData();
            massData.center = b2Vec2(x,y);
            this._b2Body.SetMassData(massData);

ps:attention to the unit,use the “PTM_RATIO”(pixel to meter)

2 Likes

Well this would work but i need it to fly so i’m gonna try moving the center on the opposite side. if this doesn’t work like i want it to i’ll try using fixtures and if that doesn’t work i’ll let you guys know :slight_smile: Thanks

but if i change the engine isn’t everything else’s center gonna change too?

the solution just need you to package the setMassData func of box2d,then you can use the packaged api where you need it.

1 Like

hey i don’t know how i’m going to package it any links for help maybe ?

hey? @Big_Bear

hey @Big_Bear i’m still waiting for your reply :blush: thanks

@slackmoehrle hey ok i think can you tell me more about fixtures because i can’t find anything about them that i understand any JS documents for that? (edited since i can’t reply more than 3 consecutively)

Let me find out what references we have

1 Like

Found anything?

edit: sorry for being a pain in the ass but this is kind of what’s holding me on development of the game and i kind of have this goal to publish it before new year because i’ve been procastinating for too long :grimacing:

edit1: @slackmoehrle

I thought one of the demos we had used spine. I’ll try to find it.

1 Like

Thanks so much :blush:

The engineering team said to take a look at this demo: https://github.com/cocos-creator/example-cases

what should i be looking at i don’t know i don’t see anything related to physics am i supposed to do this spine thing ?

@slackmoehrle

Hey can you tell me how am i gonna package setMassData func of box2d please???

@Big_Bear