/*REMINDER: (declared above) * * private Rectangle cBallHitBox; * private Circle cBall; * private Circle cBallNext;*/ void UpdateCbNextAndHitbox() { yNext = cBall.center.y * cb.damp + cb.viy * Time.deltaTime; if (cBall.center.y > 8.3f) { wind = cloud.getWind(); //when the cannonball is above the stonehedge } else { wind = 0; } // viyNext = cb.viy - cb.gravity * Time.deltaTime; //i dont think i need this xNext = cBall.center.x * cb.damp + cb.vix * Time.deltaTime + wind * Time.deltaTime; //update cBallNext cBallNext.setCenter(new Vector2(xNext, yNext)); Vector2 centerToNext = new Vector2(cBallNext.center.x - cBall.center.x, cBallNext.center.y - cBall.center.y); Vector2 norm = new Vector2(centerToNext.y, -centerToNext.x); //centerToNext and norm are perpendicular, aka centerToNext dot norm = 0 norm.Normalize(); //four corners of rectangle hit box Vector2 a = new Vector2(cBall.center.x - radius * norm.x, cBall.center.y - radius * norm.y); Vector2 b = new Vector2(cBall.center.x + radius * norm.x, cBall.center.y + radius * norm.y); Vector2 c = new Vector2(cBallNext.center.x + radius * norm.x, cBallNext.center.y + radius * norm.y); Vector2 d = new Vector2(cBallNext.center.x - radius * norm.x, cBallNext.center.y - radius * norm.y); //update hitbox cBallHitBox.setCorners(a, b, c, d); }
public void MoveCannonball() { y = y * damp + viy * Time.deltaTime; if (y > 8.3f) { wind = cloud.getWind(); //when the cannonball is above the stonehedge } else { wind = 0; } viy -= gravity * Time.deltaTime; x = x * damp + vix * Time.deltaTime + wind * Time.deltaTime; transform.position = new Vector3(x, y, 1); }