void ASpaceRocksPawn::SideThrust(float val) { // ** Player is Firing the Side Thrusters ** // ** The orientation/rotation of the Root component is always fixed. ** // ** So, speed up/slow down on each axis is based on the direction vector of where the player's craft mesh is pointing ** float x_factor = 0.f; float y_factor = 0.f; float z_factor = 0.f; FVector Up = PlaneMesh->GetRightVector(); // ** Let's First calculate forward speed (aka X axis speed) ** x_factor = Up.X; CurrentXAxisSpeed = CalcThrust(val, x_factor, CurrentXAxisSpeed); // ** Now for Y axis y_factor = Up.Y; CurrentYAxisSpeed = CalcThrust(val, y_factor, CurrentYAxisSpeed); // ** Now for Z axis speed ** z_factor = Up.Z; CurrentZAxisSpeed = CalcThrust(val, z_factor, CurrentZAxisSpeed); }
//typedef enum { Up, UpRight, Right, DownRight, Down, DownLeft, Left, UpLeft, None } Direction; void Ship::PlayerUpdate() { // Be clever and arrange the enums so you can do a bit mask? if ( DPad == UpLeft || DPad == Left || DPad == DownLeft ) { ShipRotation -= RotationRate * DeltaTime; ( ShipRotation > 360 ) ? ShipRotation -= 360 : ( ( ShipRotation < 0 ) ? ShipRotation += 360 : ShipRotation ); } else if (DPad == UpRight || DPad == Right || DPad == DownRight ) { ShipRotation += RotationRate * DeltaTime; ( ShipRotation > 360 ) ? ShipRotation -= 360 : ( ( ShipRotation < 0 ) ? ShipRotation += 360 : ShipRotation ); } int rotation = ShipRotation / 45; ShipFacing = static_cast<Direction>( rotation ); // 28,200 -> 28,138 PlayerShip->BitMap = PlayerBitMaps[ShipFacing]; // Friction if (! ( DPad == Up || DPad == UpRight || DPad == UpLeft ) ) { Vector2d friction = *Velocity; friction = friction * -1.0f * ShipFriction * DeltaTime; *Velocity += friction; } Vector2d thrust = Vector2d( 0, 0 ); if ( DPad == Up || DPad == UpRight || DPad == UpLeft ) thrust = CalcThrust( ShipFacing ); else if ( DPad == Down || DPad == DownRight || DPad == DownLeft ) thrust = CalcThrust( ShipFacing ) * -0.4f; UpdateMovement( thrust ); { TimeUntilNextRepair -= DeltaTime; if ( TimeUntilNextRepair <= 0 ) { TimeUntilNextRepair = RepairTime;// + ( RepairTime * 10 - RepairTime * 10 * Crew / Max_Crew ); RepairSystem(); } } }
void ASpaceRocksPawn::BottomThrust(float val) { // ** Player is Firing the Bottom/Top Thrusters ** // ** The orientation/rotation of the Root component is always fixed. ** // ** So, speed up/slow down on each axis is based on the direction vector of where the player's craft mesh is pointing ** float x_factor = 0.f; float y_factor = 0.f; float z_factor = 0.f; FVector Up = PlaneMesh->GetUpVector(); //float x = Up.X; //float y = Up.Y; //float z = Up.Z; //GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, FString::Printf(TEXT("Pitch = %f, Roll = %f, Yaw = %f"), craftorientation.getPitchDegs(), craftorientation.getRollDegs(), craftorientation.getYawDegs())); //GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("Pitch = %f, Roll = %f, Yaw = %f"), craftorientation.getPitchFactor(0), craftorientation.getRollFactor(0), craftorientation.getYawFactor(0))); // ** Let's First calculate forward speed (aka X axis speed) ** x_factor = Up.X; //GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("vX = %f, vY = %f, vZ = %f"), x,y,z)); //GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::Printf(TEXT("X factor = %f"), x_factor)); CurrentXAxisSpeed = CalcThrust(val, x_factor, CurrentXAxisSpeed); // ** Now for Y axis y_factor = Up.Y; //GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::Printf(TEXT("Y factor = %f"), y_factor)); CurrentYAxisSpeed = CalcThrust(val, y_factor, CurrentYAxisSpeed); // ** Now for Z axis speed ** z_factor = Up.Z; //GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::Printf(TEXT("Z factor = %f"), z_factor)); CurrentZAxisSpeed = CalcThrust(val, z_factor, CurrentZAxisSpeed); }