@Override
public void update(float dt) {
mRotation -= mEngine.mControl.mHorizontalFactor * (mMaxRotationSpeed * dt);
//float accel = mEngine.mControl.mVerticalFactor * mThrust;
float accel = 0f;
if(mEngine.mControl.mJump) { //accelerator button, instead of joystick input
accel = mThrust;
float angle = (mRotation+90) * TO_RADIANS; //note, +90 deg!
float ax = (float) Math.cos(angle) * accel;
float ay = (float) Math.sin(angle) * accel;
mVelX += ax*dt;
mVelY += ay*dt;
mVelX = Utils.clamp(mVelX, -mMaxVelocity, mMaxVelocity);
mVelY = Utils.clamp(mVelY, -mMaxVelocity, mMaxVelocity);
}else{
mVelX *= mFriction; //break when there's no input
mVelY *= mFriction;
}
mPos.x += mVelX;
mPos.y += mVelY;
}
Comments
0 B
|0 👍
/0 👎
0 B
|👍
/👎