当前位置: 首页>>代码示例>>Golang>>正文


Golang Vehicle.Velocity方法代码示例

本文整理汇总了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
	}
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:27,代码来源:physics.go

示例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
	}
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:11,代码来源:acceleration.go

示例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
		}
	}
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:14,代码来源:physics.go

示例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
	}

}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:25,代码来源:physics.go


注:本文中的github.com/awesomegroupidunno/game-server/state.Vehicle.Velocity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。