Author Topic: Axe Pseudo-physics help?  (Read 5314 times)

0 Members and 2 Guests are viewing this topic.

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Axe Pseudo-physics help?
« on: March 11, 2014, 01:21:19 pm »
I need help with calculations for bouncing a ball off of a moving, curved surface (and one static, straight one). I know that trig is involved, but I don't know exactly what calculations to make (and since articles are still being ported through SMFs, that's no help)!


Help? :-\
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: Axe Pseudo-physics help?
« Reply #1 on: March 11, 2014, 02:32:54 pm »
Okay so I've never done that before, but I gave it a quick think and that's what I thought of.

Let's say you have a curved surface sprite that is 16 pixels wide. Let's make it look like this :



Now you have to build a 16-entries normal angles table. By that I mean a table that will hold 16 values, one for each X coordinate on the sprite, and which will represent the normal angle of the pixel on that coordinate. I don't think you have to calculate them, just guess them based on what you see. Of course, they had to be in the range 0-255 and not 0-359.



Using these angles requires all of your velocities to use polar coordinates. That means that your ball will not have X, Y, VX and VY coordinates (VX and VY being velocity amount for X and Y coordinates), but X, Y, VR and VT coordinates. X and Y will be your ball's coordinates on the screen, like you always used them, but VR and VT will be the polar coordinate for your velocity vector - respectively the length and the angle.

When you hit a pixel - I'll let collisions to you - just grab the X coordinate of the pixel relative to the start of the sprite, get the corresponding angle in the normal angles table and apply symmetry with the velocity angle - I think you'd do velocityAngle += (pixelNormal - velocityAngle) * 2. Then that should be good.

Of course you will have to write the code to handle polar velocity. You might want to apply trig on the angle and multiply the result by the length, to add both results (X and Y) to the ball's coordinates.

Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: Axe Pseudo-physics help?
« Reply #2 on: March 11, 2014, 02:39:37 pm »
The curved surface is moving at a static speed, right? If you treat the collision like a static collision, but apply the curved surface's velocity as an offset to the ball's velocity, then subtract that offset from the result, you get the correct result.

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Re: Axe Pseudo-physics help?
« Reply #3 on: March 11, 2014, 04:56:49 pm »
The curved surface is moving at a static speed, right? If you treat the collision like a static collision, but apply the curved surface's velocity as an offset to the ball's velocity, then subtract that offset from the result, you get the correct result.
Left and right, it will be constant. I'll make the curved object bounce on command, though.
Okay so I've never done that before, but I gave it a quick think and that's what I thought of.

Let's say you have a curved surface sprite that is 16 pixels wide. Let's make it look like this :



Now you have to build a 16-entries normal angles table. By that I mean a table that will hold 16 values, one for each X coordinate on the sprite, and which will represent the normal angle of the pixel on that coordinate. I don't think you have to calculate them, just guess them based on what you see. Of course, they had to be in the range 0-255 and not 0-359.



Using these angles requires all of your velocities to use polar coordinates. That means that your ball will not have X, Y, VX and VY coordinates (VX and VY being velocity amount for X and Y coordinates), but X, Y, VR and VT coordinates. X and Y will be your ball's coordinates on the screen, like you always used them, but VR and VT will be the polar coordinate for your velocity vector - respectively the length and the angle.

When you hit a pixel - I'll let collisions to you - just grab the X coordinate of the pixel relative to the start of the sprite, get the corresponding angle in the normal angles table and apply symmetry with the velocity angle - I think you'd do velocityAngle += (pixelNormal - velocityAngle) * 2. Then that should be good.

Of course you will have to write the code to handle polar velocity. You might want to apply trig on the angle and multiply the result by the length, to add both results (X and Y) to the ball's coordinates.
...I'm assuming this works with falling with proper accel, right? :-\
« Last Edit: March 11, 2014, 05:01:19 pm by JWinslow23 »
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: Axe Pseudo-physics help?
« Reply #4 on: March 19, 2014, 10:43:29 am »
Well yes, you'll have to handle that. It's pretty easy as soon as you're familiar with binary trigonometry.

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Re: Axe Pseudo-physics help?
« Reply #5 on: March 19, 2014, 04:39:29 pm »
Well yes, you'll have to handle that. It's pretty easy as soon as you're familiar with binary trigonometry.
I am not. :(
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Axe Pseudo-physics help?
« Reply #6 on: March 19, 2014, 05:16:14 pm »
Well yes, you'll have to handle that. It's pretty easy as soon as you're familiar with binary trigonometry.
knowing JWinslow's age, I doubt he even had the chance to learn trig in depth yet. Probably in 2 years if it's similar to Canada and even then, in Canada, it was optional.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: Axe Pseudo-physics help?
« Reply #7 on: March 20, 2014, 02:35:05 am »
Oh ... :/ well I don't know your age, but there are many things you can't do if you don't know trig. Including this. And sorry but I don't feel like doing the work of your future math teacher ; trigonometry is something complicated and I don't know your grade (don't really know how to say it, the year you're in I guess).

Offline TheCoder1998

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 434
  • Rating: +20/-2
  • my art is written in code, not in graphite
    • View Profile
    • My website :D
Re: Axe Pseudo-physics help?
« Reply #8 on: March 20, 2014, 02:49:45 am »
if i were you, i should look up some turorials about trigonometry.
then you'll understand most of how to do what you want to do
my ticalc acc:

http://www.ticalc.org/archives/files/authors/113/11365.html

Spoiler For The Best Song Ever:


follow me on tumblr :)
www.rickdepizza.tumblr.com

check out my anilist :D
http://anilist.co/animelist/29701/Rickdepizza