Hi Box2d forum,
i have a question about moving an object in a beziere curve. At the moment the object can move in a curve way, but i want to set the speed or the duration how long the object need to move along the beziere curve path. Here is the update method of the object:
As you can see i use the "SetLinearVelocity" to move the object. The problem is when i increase x and y the object is to fast and doesnt follow the correct bezier curve path. So my question is how can i add x and y to the object to move it without having this problem. Or does anyone has an example of how box2d object follow bezier curve paths.
I hope anyone can understand me.
Thank you in advance.
i have a question about moving an object in a beziere curve. At the moment the object can move in a curve way, but i want to set the speed or the duration how long the object need to move along the beziere curve path. Here is the update method of the object:
Code: Select all
static inline CGFloat bezierat( float a, float b, float c, float d, ccTime t )
{
return (powf(1-t,3) * a +
3*t*(powf(1-t,2))*b +
3*powf(t,2)*(1-t)*c +
powf(t,3)*d );
}
-(void)update:(ccTime)delta{
CGFloat xa = 0;
CGFloat xb = _config.controlPoint_1.x;
CGFloat xc = _config.controlPoint_2.x;
CGFloat xd = _config.endPosition.x;
CGFloat ya = 0;
CGFloat yb = _config.controlPoint_1.y;
CGFloat yc = _config.controlPoint_2.y;
CGFloat yd = _config.endPosition.y;
CGFloat x = bezierat(xa, xb, xc, xd, delta);
CGFloat y = bezierat(ya, yb, yc, yd, delta);
x /= PTM_RATIO;
y /= PTM_RATIO;
_physicalBody->SetLinearVelocity(b2Vec2(x,y));
}
As you can see i use the "SetLinearVelocity" to move the object. The problem is when i increase x and y the object is to fast and doesnt follow the correct bezier curve path. So my question is how can i add x and y to the object to move it without having this problem. Or does anyone has an example of how box2d object follow bezier curve paths.
I hope anyone can understand me.
Thank you in advance.