Esempio n. 1
0
// Creates knockback for a vehicle
func (p *Physics) VehicleKnockback(vehicle *state.Vehicle, kbAngle, kbVelocity float64) {
	// Get vehicle velocity vectors
	vehAngleX, vehAngleY := splitComponent(vehicle.Angle)
	vehVectorX := vehAngleX * vehicle.Velocity
	vehVectorY := vehAngleY * vehicle.Velocity

	// Get knockback velocity vectors
	kbAngleX, kbAngleY := splitComponent(kbAngle)
	kbVectorX := kbAngleX * kbVelocity
	kbVectorY := kbAngleY * kbVelocity

	// Combine vectors
	vectorX := vehVectorX + kbVectorX
	vectorY := vehVectorY + kbVectorY
	vehVelocity := combineComponents(vectorX, vectorY)

	// Calculate angle perpendicularity as a percent
	angleFactor := math.Mod(math.Abs(vehicle.Angle-kbAngle+90), 180) / 90.0

	// Set vehicle velocity
	if math.Signbit(vehicle.Velocity) == math.Signbit(vehVelocity) {
		vehicle.Velocity = -vehVelocity * angleFactor
	} else {
		vehicle.Velocity = vehVelocity * angleFactor
	}
}
func (t *AccelerationCommandProcessor) accelerateVehicle(v *state.Vehicle, c *cmd.AccelerationCommand) {
	v.Velocity = v.Velocity + (c.Value * t.Physics.AccelerationCommandModifier)

	if v.Velocity >= t.Physics.MaxVehicleVelocity {
		v.Velocity = t.Physics.MaxVehicleVelocity
	}

	if (v.Velocity) <= (-1 * t.Physics.MaxVehicleVelocity) {
		v.Velocity = -1 * t.Physics.MaxVehicleVelocity
	}
}
Esempio n. 3
0
func (p *Physics) VehicleFrictionSlow(vehicle *state.Vehicle, duration time.Duration) {
	speedLoss := p.FrictionSpeedLoss * duration.Seconds()
	if vehicle.Velocity > 0 {
		vehicle.Velocity = float64(vehicle.Velocity) - float64(speedLoss)
		if vehicle.Velocity < 0 {
			vehicle.Velocity = 0
		}
	} else {
		vehicle.Velocity = float64(vehicle.Velocity) + float64(speedLoss)
		if vehicle.Velocity > 0 {
			vehicle.Velocity = 0
		}
	}
}
Esempio n. 4
0
func (p *Physics) VehicleBounding(v *state.Vehicle) {
	shouldStop := v.X < 0

	if shouldStop {
		v.X = 2
	}

	if v.Y < 0 {
		shouldStop = true
		v.Y = 2
	}

	if v.Y > p.WorldHeight {
		shouldStop = true
		v.Y = p.WorldHeight - 2
	}
	if v.X > p.WorldWidth {
		shouldStop = true
		v.X = p.WorldWidth - 2
	}
	if shouldStop {
		v.Velocity = 0
	}

}