本文整理汇总了C#中FarseerPhysics.Common.Path.GetPosition方法的典型用法代码示例。如果您正苦于以下问题:C# Path.GetPosition方法的具体用法?C# Path.GetPosition怎么用?C# Path.GetPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FarseerPhysics.Common.Path
的用法示例。
在下文中一共展示了Path.GetPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MoveBodyOnPath
//TODO: Comment better
/// <summary>
/// Moves the body on the path.
/// </summary>
/// <param name="path">The path.</param>
/// <param name="body">The body.</param>
/// <param name="time">The time.</param>
/// <param name="strength">The strength.</param>
/// <param name="timeStep">The time step.</param>
public static void MoveBodyOnPath(Path path, Body body, float time, float strength, float timeStep)
{
Vector2 destination = path.GetPosition(time);
Vector2 positionDelta = body.Position - destination;
Vector2 velocity = (positionDelta / timeStep) * strength;
body.LinearVelocity = -velocity;
}
示例2: MoveBodyOnPath
//TODO: Comment better
/// <summary>
/// Moves the body on the path.
/// </summary>
/// <param name="path">The path.</param>
/// <param name="body">The body.</param>
/// <param name="time">The time.</param>
/// <param name="strength">The strength.</param>
/// <param name="timeStep">The time step.</param>
public static void MoveBodyOnPath(Path path, Body body, float time, float strength, float timeStep, bool if_type2 = true)
{
Vector2 destination = path.GetPosition(time);
Vector2 positionDelta = body.Position - destination;
if ( positionDelta.Length() != 0 )
positionDelta.Normalize(); // Added for game
Vector2 velocity = (positionDelta / timeStep) * strength;
Vector2 vel = Math.Min(8,body.LinearVelocity.Length()+3) * -velocity * body.Mass;
if (if_type2 && vel.Length() > 1)
{
float velocity_magnitude_X = Math.Abs(body.LinearVelocity.X);
float velocity_magnitude_Y = Math.Abs(body.LinearVelocity.Y);
float force_magnitude_X = Math.Abs(vel.X);
float force_magnitude_Y = Math.Abs(vel.Y);
bool horiz = force_magnitude_X > 2;
bool vert = force_magnitude_Y > 2;
bool high_vert_low_horiz = (velocity_magnitude_X < velocity_magnitude_Y - 10);
bool high_horiz_low_vert = velocity_magnitude_X > velocity_magnitude_Y + 10;
if ((horiz) && high_vert_low_horiz)
{
vel.X *= 2f;
vel.Y /= 2f;
//body.LinearVelocity = new Vector2(body.LinearVelocity.X,body.LinearVelocity.Y/1.5f);
}
if (vert && high_horiz_low_vert)
{
vel.Y *= 2f;
vel.X /= 2f;
// body.LinearVelocity = new Vector2(body.LinearVelocity.X/1.5f, body.LinearVelocity.Y);
}
if (Math.Sign(vel.Y) != Math.Sign(body.LinearVelocity.Y))
{
vel.Y *= 3;
}
if (Math.Sign(vel.X) != Math.Sign(body.LinearVelocity.X))
{
vel.X *= 3;
}
body.ApplyForce(vel);
}
else if(path.GetLength()>0.5f)
{
body.LinearVelocity = -velocity;
}
}