Я проходил обучение и большую часть понял. Я хочу спросить 1 вещь. Это учебник, которому я следую:
https://noobtuts.com/unity/2d-pong-game
Это метод, который называется функцией HitFactor.
if (col.gameObject.name == "RacketLeft") {
// Calculate hit Factor
float y = hitFactor(transform.position, col.transform.position, col.collider.bounds.size.y);
// Calculate direction, make length=1 via .normalized
Vector2 dir = new Vector2(1, y).normalized;
// Set Velocity with dir * speed
GetComponent<Rigidbody2D>().velocity = dir * speed;
}
И метод Hit Factor
float hitFactor(Vector2 ballPos, Vector2 racketPos,
float racketHeight) {
// ascii art:
// || 1 <- at the top of the racket
// ||
// || 0 <- at the middle of the racket
// ||
// || -1 <- at the bottom of the racket
return (ballPos.y - racketPos.y) / racketHeight;
}
Может ли кто-нибудь объяснить мне это на примере?
(ballPos.y - racketPos.y) / racketHeight;
Я действительно не могу понять и не знаю, что я должен прочитать, чтобы понять это.