2d "camera" follow target looks ugly

I just tried this:

  • adding another Node as child, and adding a body to this new child
    and the result is very confusing:

THE SPRITE THAT CAMERA FOLLOWS… JITTERS (same as old video)… BUT HIS CHILD… LOOKS PERFECT

auto child = cocos2d::Node::create();
auto newBody = cocos2d::PhysicsBody::create();
auto shape = cocos2d::PhysicsShapeCircle::create(50);
shape->setSensor(true);
newBody->addShape(shape);
newBody->setDynamic(false);
newBody->setPositionOffset({ 30,0 });

child->setPhysicsBody(newBody);
sprite->addChild(child);

… WTF

The problem still the same…
any idea?? @slackmoehrle @zhangxm

I just created this question, that looks like the same problem… Im just hoping to solve the problem… thnx

Solution is there 2d "camera" follow target looks ugly

Repeating question and ignoring links for solution will not help you)
Also you can google for smoothDamp function implementation from unity, it’s filtering camera super smoothly.

Im sorry, but I have try (if Im correct) every and each single solution has been presented here.

The “solution” you mentioned here:[quote=“KAMIKAZE, post:7, topic:36509”]
Long time ago I’ve faced the same problem. That was cocos2d-iphone. Solution was - update physics and camera at same -(void) update: method. Worked well.
[/quote]

I am actually implementing it:

  • setup:

    getPhysicsWorld()->setAutoStep(false);
    getPhysicsWorld()->setSpeed(5.0f);
    getPhysicsWorld()->setGravity(Vec2(0, -98));
    schedule(schedule_selector(GS_1::MyUpdate), 1.0f / 90.0f);

-update:

void GS_1::MyUpdate(float dt)
{
    getPhysicsWorld()->step(dt);
    actionLayer->update(dt);
    getDefaultCamera()->setPosition(cameraTarget->getPhysicsBody()->getPosition());
    getDefaultCamera()->update(dt);
}

Also, I implemented the solution mentioned in the links you provided
(How to fix Jittery Side Scrolling with Box2D) & (Fixed Time Step and Box2D)
and even if using all of these methods kinda solves or make it less obvious the problem of the jittering on the camera, some “secondary effect” persists, like the fact that children’s bodies have a small delay, seems like thery are updated at a diferent time.

I appreciate your solutions and clarifications, specially from you (@anon98020523) and (@almax27). You have helped me a lot. And now I could say the jiterring is not bothering me anymore.

I just think that this “secondary effect” is part of the same problem. I dont think im repeating a question, and definitely im not ignoring any answer (I even made a list of the result of each answer given). I think I am showing another side effect of the same problem which current solutions does not fix.

I created another thread because I think If someone else search specifically for it would be easier to find, and I dont consider it the exact same question. But…to be honest, seems like if anyone knows (and answers) in this forum is mainly both of you (and some how I think is conected to this issue)

I repeat: now I could say the jiterring is not bothering me anymore, So I guess I wil set this as solved.
Thanks everyone for the help, I really appreciate it.

Hi!

I am new to Cocos2d and had the same (worst!) problem. After some debugging I discovered that when a scene is created, a new camera is added. If you look closely, you see that when the scene starts, there are 2 (same) cameras!
To fix that, I went to cocos2d::CCCamera::setScene(~line 451) and replaced the code:

// FX:: 25/09/2017??? auto it = std::find(cameras.begin(), cameras.end(), this);
//if (it == cameras.end())
with this
if (cameras.size() < 1)

after that everything works perfectly.

(NB: I use windows10/C++ 2017)

1 Like

Can you please create a GitHub issue for this?

I am sorry, but as a noobie, I must ask.

How should I do that?

Here, please: https://github.com/cocos2d/cocos2d-x/issues

Thank you. I did so, and the new issue id is: Scene cameras #18320