本文整理汇总了C#中Vehicle.OnCollision方法的典型用法代码示例。如果您正苦于以下问题:C# Vehicle.OnCollision方法的具体用法?C# Vehicle.OnCollision怎么用?C# Vehicle.OnCollision使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vehicle
的用法示例。
在下文中一共展示了Vehicle.OnCollision方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleNonCarCollision
private void HandleNonCarCollision(Vehicle vehicle, NonCar nonCar, Vector3 pos, Vector3 patchnormal, Vector3 normalforce, ContactPairFlag events)
{
if (nonCar.LastTouchTime + 0.1f > Engine.TotalSeconds)
{
nonCar.LastTouchTime = Engine.TotalSeconds;
return;
}
nonCar.LastVehicleToHit = vehicle;
if (nonCar.IsAttached)
{
if (normalforce == Vector3.Zero) return;
nonCar.Hit = true;
float speed = vehicle.Chassis.LastSpeeds.GetMax();
if (speed < 20) return;
normalforce = Vector3.Normalize(normalforce);
Vector3 directedForce = normalforce * speed * vehicle.Config.Mass;
float factor = (1 / (nonCar.Config.TorqueRequiredToMove * nonCar.Config.MassWhenAttached)) * 0.005f;
nonCar.Rotation.X += -directedForce.X * factor;
nonCar.Rotation.Z += directedForce.Z * factor;
nonCar.LastTouchTime = Engine.TotalSeconds;
nonCar.LastForcePosition = pos;
nonCar.LastForce = directedForce;
//multiply force to match the force generated by hitting a solid wall/barrier etc
vehicle.OnCollision(directedForce.Length() * 15, pos, normalforce, true);
}
else
{
vehicle.OnCollision(normalforce.Length(), pos, normalforce, false);
}
nonCar.LastTouchTime = Engine.TotalSeconds;
}