Reputation: 2206
So in my game a have this paddle and a ball, and i want to calculate which side of the paddle that the ball hits, i found this answer in C# which shows drawing two lines like this:
So what i want to do is draw two hypothetical lines(meaning invisible to the user) so i can calculate if the ball is greater then both the lines or if its in contact with one of the sides of the paddle.
How do i draw these lines in sprite kit and swift?
UPDATE
I found the original answer, its HERE
Upvotes: 1
Views: 168
Reputation: 11696
You can check the position of the ball in relation to the paddle.
If(ballNode.position.x > paddleNode.position.x) {
// ball is on the right of the paddle
} else {
// ball is on the left of the paddle
}
If(ballNode.position.y > paddleNode.position.y) {
// ball is above the paddle
} else {
// ball is below the paddle
}
Upvotes: 3