本文整理汇总了Golang中github.com/awesomegroupidunno/game-server/state.Vehicle.Velocity方法的典型用法代码示例。如果您正苦于以下问题:Golang Vehicle.Velocity方法的具体用法?Golang Vehicle.Velocity怎么用?Golang Vehicle.Velocity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/awesomegroupidunno/game-server/state.Vehicle
的用法示例。
在下文中一共展示了Vehicle.Velocity方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: VehicleKnockback
// 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
}
}
示例2: accelerateVehicle
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
}
}
示例3: VehicleFrictionSlow
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
}
}
}
示例4: VehicleBounding
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
}
}