View Single Post
  #15  
Old 06-19-2012, 11:42 PM
E_Man E_Man is offline
E-Man
E_Man's Avatar
Join Date: Jun 2012
Posts: 81
E_Man will become famous soon enough
Quote:
Programming languages typically work in radians instead of degrees. There's 2pi radians in a circle.



Notice how the radians on the circle (they have pi attached) compare to the degrees.

So to get the angle bullets should fly at, we can do..
PHP Code:
(player.dir + 1) * (pi / 2)
Let's say I'm facing left, which means my dir is 1.



So we can start filling in values for that expression

PHP Code:
(1 + 1) * (pi / 2)
simplifies to..

PHP Code:
2 * (pi / 2)
which simplifies using basic math to simply pi. If we look on that circle, we can see where the angle pi lies.



This is where our bullets will fly. Try the same thing for any direction and you'll find the angle matches up to the direction the player is facing.

Ok, now I completely understand this. Thank you for sending this. I was even able to fix your shorted script that you said earlier

Quote:
Shoot inherits basic gani properties. In this case you can just set the graphics in the gani for each direction and they will be set automatically when fired. You can also simplify the script like so:

PHP Code:
if (weaponfired) {
freezeplayer 0.6;
setani shoot,woodenbow1.png;
sleep 0.2;
shoot playerx-0.8,playery+0.5,2,pi/2*playerdir,0,0,eman_woodenarrow,;
}
You just needed to do this
PHP Code:
if (weaponfired) {
  
freezeplayer 0.6;
  
setani shoot,woodenbow1.png;
  
sleep 0.2;
  
shoot playerx-0.8,playery+0.5,2,pi/2*(playerdir+1),0,0,eman_woodenarrow,;

As you can see, I jst slightly changed the pi/2*playerdir to pi/2*(playerdir+1) because it was shooting 90 degrees more than it should have. But I don't think this script could work shortened because when you try shooting in different directions, the bow gani changes where the bow is coming from so you can't do playery+# and playerx+# because it changes. But just so no one forgets, I will just mention that I still need to figure out how to damage baddy npcs.
Reply With Quote