我有一个360度旋转的雪碧枪,我不想让它朝任何方向发射子弹,我该怎么做?我不能简单地增加子弹的x,y坐标,因为它会向上,向下,向左,向右。
编辑:项目符号移动似乎只会旋转,但不会移动到任何地方或屏幕之外
bulletPosition.x=MathUtils.cosDeg(cannonObj.cannonAngle())*2;
bulletPosition.y=MathUtils.sinDeg(cannonObj.cannonAngle())*2;
bulletVelocity.x=MathUtils.cosDeg(cannonObj.cannonAngle())*10;
bulletVelocity.y=MathUtils.sinDeg(cannonObj.cannonAngle())*10;
bulletPosition.x+=bulletVelocity.x*deltaTime;
bulletPosition.y+=bulletVelocity.y*deltaTime;
//spawning bullets
public void draw(SpriteBatch batch){
bulletIterator=bullets.iterator();
while(bulletIterator.hasNext()){
Sprite sprite=bulletIterator.next();
sprite.draw(batch);
sprite.setPosition(bulletPosition.x,bulletPosition.y);
}发布于 2015-08-02 16:42:50
Vector gunPos; // the gun position,dah
Vector bulletPos; //the bullet position
Vector bulletVelocity; //need explanation?
float gunAngle; //the rotation of the gun in degrees
float distanceFromCenter=gunSize.x/2; //the distance from the gun center you want the bullet to appear
bulletPos.x=MathUtils.cosDeg((gunAngle)) * distanceFromCenter;
bulletPos.y=MathUtils.cosDeg((gunAngle)) * distanceFromCenter;
bulletPos.plus(gunPos);
bulletVelocity.x=MathUtils.cosDeg((gunAngle)) * bulletSpeed;
bulletVelocity.y=MathUtils.cosDeg((gunAngle)) * bulletSpeed;https://stackoverflow.com/questions/31762144
复制相似问题