Welcome, Guest. Please login or register.

Author Topic: Angle of deflection  (Read 3324 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline motorollinTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 8669
    • Show all replies
Angle of deflection
« on: August 14, 2007, 02:36:52 PM »


Assuming the ball is travelling at constant velocity with no spin, is it possible to calculate its angle of deflection given the angle in degrees in which it is travelling and on which side of the box it impacts?

--
moto
Code: [Select]
10  IT\'S THE FINAL COUNTDOWN
20  FOR C = 1 TO 2
30     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NAAAA
40     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NA-NA-NAAAAA
50  NEXT C
60  NA-NA-NAAAA
70  NA-NA NA-NA-NA-NA-NAAAA NAAA-NAAAAAAAAAAA
80  GOTO 10
 

Offline motorollinTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 8669
    • Show all replies
Re: Angle of deflection
« Reply #1 on: August 14, 2007, 03:35:27 PM »
For some reason this doesn't quite work in the application I'm writing. Here's what happens:

1. Sprite starts moving at 45 degrees to the horizontal.
2. Collision with right edge of playfield
3. Sprite deflects at 135 degrees to horizontal (180-45)
4. Sprite starts moving at 135 degrees to horizontal
5. Collision with top edge of playfield
6. Sprite deflects at 45 degrees to horizontal (180-135)

Step 6 means that the sprite exist the playfield at 45 degrees instead of bouncing back in to it as it should :-?

--
moto
Code: [Select]
10  IT\'S THE FINAL COUNTDOWN
20  FOR C = 1 TO 2
30     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NAAAA
40     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NA-NA-NAAAAA
50  NEXT C
60  NA-NA-NAAAA
70  NA-NA NA-NA-NA-NA-NAAAA NAAA-NAAAAAAAAAAA
80  GOTO 10
 

Offline motorollinTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 8669
    • Show all replies
Re: Angle of deflection
« Reply #2 on: August 14, 2007, 03:41:00 PM »
Oh I bet it's because it doesn't know which side it has collided with, only that it has collided. If that last collision had been with an object to the ball's right then a 45 degree deflection would have been correct. So I suppose I need to calculate which side it impacts on and whether the angle change would cause the ball to leave the playfield, and if it would then add 180 degrees to the angle to turn the ball round back in to the playfield.

Urgghhh...

--
moto
Code: [Select]
10  IT\'S THE FINAL COUNTDOWN
20  FOR C = 1 TO 2
30     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NAAAA
40     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NA-NA-NAAAAA
50  NEXT C
60  NA-NA-NAAAA
70  NA-NA NA-NA-NA-NA-NAAAA NAAA-NAAAAAAAAAAA
80  GOTO 10
 

Offline motorollinTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 8669
    • Show all replies
Re: Angle of deflection
« Reply #3 on: August 14, 2007, 03:53:46 PM »
The problem is that the language I am using doesn't use "move the sprite y pixels up/down and/or x pixels left/right", it uses "set the sprite's angle of movement to a and its velocity to v". So I can't just tell it to move down. I have to tell it which angle to move in.

I think I've figured it out though. Karlos' rule of 180-angle works for the left and right sides. For the top and bottom, (180-angle)+180 seems to work. These are in hand-drawn tests I have just done. I'm going to reboot in to Windows now and test it in the game.

--
moto
Code: [Select]
10  IT\'S THE FINAL COUNTDOWN
20  FOR C = 1 TO 2
30     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NAAAA
40     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NA-NA-NAAAAA
50  NEXT C
60  NA-NA-NAAAA
70  NA-NA NA-NA-NA-NA-NAAAA NAAA-NAAAAAAAAAAA
80  GOTO 10
 

Offline motorollinTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 8669
    • Show all replies
Re: Angle of deflection
« Reply #4 on: August 14, 2007, 04:07:43 PM »
It works :-D I have four separate invisible ¨barriers¨ - one along each side of the playfield. Collision with the left or right barriers sets the angle of the object to 180-angle, and collision with the top or bottom barriers sets the angle of the object to (180-angle)+180. I might just add ¨+rand(10)¨ or similar to give some variation, otherwise the object eventually falls in to the same square movement.

Thanks guys!

--
moto
Code: [Select]
10  IT\'S THE FINAL COUNTDOWN
20  FOR C = 1 TO 2
30     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NAAAA
40     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NA-NA-NAAAAA
50  NEXT C
60  NA-NA-NAAAA
70  NA-NA NA-NA-NA-NA-NAAAA NAAA-NAAAAAAAAAAA
80  GOTO 10