【发布时间】:2021-12-30 22:38:54
【问题描述】:
这是我第一次在这里提问,很抱歉,如果我没有说出需要的一切,请随时询问更多信息。
基本上,我正在创建一个使用加速度移动的玩家角色,如下所示:
velocity.X += movingDir * acceleration - friction * velocity.X;
velocity.Y += gravityScale * gravityVector //Vector2(0,9.81f * gravityScale)
if (normalMouvement)
velocity.X = Math.Clamp(velocity.X, -maxSpeed, maxSpeed);
我想让玩家在按下 A 时附在绳子上,然后绕着绳子摆动直到他松开 A。玩家已经有了一个起始速度,该速度会随着绳子摆动而改变(例如,如果我按下左键向右摆动时,我会摆动得更慢)。绳子的附着位置已经定义好了。
(我知道这是高级艺术哇)
我在阅读 this article 后尝试过这样做:
if (Input.GetKeyDown(Keys.A))
distanceToGrapplingPoint = (Platformer.Map.data.grapplingPoints[0].Pos - Pos).Length();
if (Input.GetKey(Keys.A))
Swing();
//this is in the Update Method
private void Swing()
{
Vector2 distance = Vector2.Normalize(Platformer.Map.data.grapplingPoints[0].Pos - Pos) * distanceToGrapplingPoint;
Vector2 gravityTension = -Vector2.Normalize(distance) * gravityVector.Y * gravityScale * distance.Y / distance.Length();
Vector2 centripetalForce = distance * gravityVector.Y * gravityScale * (velocity / distance.Length()) * (velocity / distance.Length());
Vector2 totalTension = gravityTension + centripetalForce;
velocity += totalTension;
}
但我的玩家直接飞入了抓斗点。我不想只设置玩家的位置并收工,而是实际计算绳索的张力以使代码更加模块化。
感谢您的帮助!
【问题讨论】:
-
你是在做绳索还是刚性固定距离?
标签: c# game-physics monogame