# Attaching a weigh on a rigidbody

Attaching a weigh on a rigidbody
0

#1

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

#2

#3

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

#4

because i need it to spin

#5

süper! Basarilar!

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.

#6

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.

#7

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.

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)

#8

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 Thanks

#9

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

#10

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

#11

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

#12

hey? @Big_Bear

#13

@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)

#14

Let me find out what references we have

#15

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

edit1: @slackmoehrle

#16

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

#17

Thanks so much

#18

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

#19

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

#20

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

@Big_Bear