使用 Box2d 进行抛射运动。
我需要知道如何使用 box2d 进行抛射运动。
最初,projectileTime=0; 然后我调用以下函数进行抛射运动。效果非常好。 但我想使用 box2d 实现同样的目标。据我所知Box2d只能用力工作,它不鼓励直接放置物体,那么如何使用Box2d进行抛射运动?
-(void)projectilelaunched:(ccTime)dt
{
projectileTime+=(5*dt);
double vh=v*cos(theta);
x=vh*projectileTime;
double y = x*tan(theta)- 10*((x/vh)*(x/vh))/2;
projectile.position=ccp(projectilePositionBeforeLaunched.x + x,projectilePositionBeforeLaunched.y+y);
}
I need to know how to use box2d for projectile motion.
initially, projectileTime=0;
then i call the following function for projectile motion. It works pretty good.
But i want to achieve the same thing using box2d. As far as i know Box2d works only with force, it does not encourage placing object directly, So how to use Box2d for projectile movement??
-(void)projectilelaunched:(ccTime)dt
{
projectileTime+=(5*dt);
double vh=v*cos(theta);
x=vh*projectileTime;
double y = x*tan(theta)- 10*((x/vh)*(x/vh))/2;
projectile.position=ccp(projectilePositionBeforeLaunched.x + x,projectilePositionBeforeLaunched.y+y);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 box2D,您只需要设置其初始位置和初始速度(通过
applyForce
)。 Box2d 会处理剩下的事情,比如施加重力、撞到其他物体时停止等等。With box2D, you'd only need to set its initial position and initial velocity (via
applyForce
). Box2d will take care of the rest, applying gravity, stopping when hitting other objects etc.实际上,您可以通过调用以下命令直接设置主体的位置:
Actually, you can directly set up position of the body by calling: