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

@slackmoehrle help please


#3

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


#4

because i need it to spin

bende türküm bu arada :slight_smile:


#5

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:


#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.
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)


#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 :slight_smile: 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

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)


#14

Let me find out what references we have