What I want to happen is for my player to bounce from spring to another. For example take the illustration below:
Here's my code (what I've tried to do so far). This gets called in an 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());
}
}
What currently happens is that when he jumps onto a spring his jump just continues but in slow motion for some reason. Can anyone see why my algorithm doesn't work? Let me know if the comments are unclear