Custom physicsbody 凹 by cocos2dx

Custom physicsbody 凹 by cocos2dx
0.0 0

#1

I have two questions.

1, I saw the sprite move around in the red frame. This is not a problem. But, sprites moving at high speed can pass through walls. Is this a bug?

2, I want to add a body to a dented shape. But I can not make a Physicsbody at once by PhysicsWorld rule.
So I divided it into three. This code is wrong, but what I want to do is here.
I would like to put the Physicsbody divided into three in one figure.
Please tell me the correct code. Thanks

zz

//sprite
auto sprite = Sprite::create(“aaaa.png”);
if (sprite == nullptr)
{
problemLoading("‘aaaa.png’");
}
else
{
sprite->setPosition(Vec2((visibleSize.width/2 + origin.x) +0, (visibleSize.height/2 + origin.y) -400));
}

Point spritePoints1[4] =
{
    Point(-68, 43), Point(-55, 43), Point(-55, -8), Point(-68, -8)
};

Point spritePoints2[4] =
{
Point(68, 43), Point(55, 43), Point(55, -8), Point(68, -8)
};
Point spritePoints3[4] =
{
Point(-68, -8), Point(68, -8), Point(68, -43), Point(-68, -43)
};

auto sprBody = PhysicsBody::createPolygon(spritePoints1, spritePoints2, spritePoints3, 4, PhysicsMaterial(0.0f, 0.0f, 0.5f));
sprBody->setDynamic(false);
sprite->setPhysicsBody(sprBody);
this->addChild(sprite, 1);

#2

You need continuous collision detection.


#3

Write with more info.

p.s. why forum not auto merge prev. posts?


#4

You need to set bitmasks for collisions etc


#5

Sorry what do you mean?


#6

Auto Merge Posts Questions
https://www.vbulletin.com/forum/forum/vbulletin-4/vbulletin-4-questions-problems-and-troubleshooting/413120-auto-merge-posts-questions


#7

Why is this even in this thread? It is not on topic and just pollutes the conversation.


#8

Just example of what is merging last messages in topic.


#9

Its not even related to the topic. The OP never mentioned merging anything.


#10

That makes sense.


#11

Sorry. I rewrote the explanation.


#12

Anyway really hard to read and understand you… It’s very bad EN translator you’re using probably. Good luck.


#13
  1. You need to set bitmasks It will trigger a collision event.

  2. I don’t understand this. Make 3 rectangles, give them Physics bodies, set bit masks. Put whatever you want in the middle, give it a physics body and a bitmask that is NOT the same as #1. Then the thing in the middle will bounce off the rectangles or whatever you wish to happen. It will trigger a collision event.


#14

Sorry. I know what you mean.

I have a dented shape. So I want to solve this problem by coding without using software.


#15

I solved the problem using “createEdgeChain”
Thanks