【发布时间】:2015-03-11 01:13:41
【问题描述】:
我想要让我的球员从弹簧弹跳到另一个弹簧。例如下图:
这是我的代码(到目前为止我一直在尝试做的事情)。这在 update()method 中调用
public void springCollision(Box containsSpring) {
// player object
Player player = ((Player) this.object);
// first spring
Spring boxSpring = containsSpring.getSpring();
// second spring
Spring platformSpring = containsSpring.getPartnerPlatform().getSpring();
// if player collides with first spring
if (player.getRect().overlaps(boxSpring.getRect())) {
// distance in x between first & second spring
float dx = platformSpring.getxPos()
+ platformSpring.getSprite().getWidth()
- boxSpring.getxPos() - player.getSprite().getWidth();
// distance in y between first & second spring
float dy = platformSpring.getyPos() - boxSpring.getyPos();
Vector2 directionToSpring = new Vector2(dx, dy);
// normalise vector then set player speed
player.setxSpeed(directionToSpring.nor().x);
player.setySpeed(directionToSpring.nor().y + player.getGravity());
}
}
目前发生的情况是,当他跳上弹簧时,他的跳跃仍在继续,但由于某种原因以慢动作进行。谁能看到为什么我的算法不起作用?如果 cmets 不清楚,请告诉我
【问题讨论】:
-
你的意思是他从不退缩?也许你的重力是 5,而你的弹簧是 10,所以你的重力永远不会赶上。你在哪里告诉它你在空中,不再弹跳?
标签: java android libgdx box2d collision-detection