inVINCEable
inVINCEable

Reputation: 2206

Draw a hypothetical line in swift

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:

Point of contact

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

Answers (1)

sangony
sangony

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

Related Questions