Page 1 of 1

My Arrows dont work right DX

PostPosted: Fri Jun 01, 2012 6:57 pm
by Hblade
Alright, I'm making a game called "I wanna be the hero" Yes, you heard right, another I wanna be the game. This one however is a bit different. Anyway, The player shoots arrows:
arrow_anim.png
arrow_anim.png (314 Bytes) Viewed 1673 times


(Graphics by DST btw, his 8bit things, awesome)

Anyway, heres my code for the animpos.
Code: Select all
animpos = -directional_velocity/8;


I've also tried:
Code: Select all
animpos = directional_velocity/8;



but the arrows don't appear right o.O

Re: My Arrows dont work right DX

PostPosted: Fri Jun 01, 2012 7:29 pm
by DarkParadox
The code is all wrong in the first place.
First, you have to set the angle that you're going in using direction, then set the animpos using the angle from that.
Code: Select all
angle=direction(xprevious, yprevious, x, y);
animpos=angle/45;

I also changed the animpos code to /45 since we have to divide 360 by however many frames are in our animation to get the correct number (in this case, 360 divided by 8.)

Also keep in mind, this code will only work if the arrow is moving, but of course it's an arrow, so it will be.

Re: My Arrows dont work right DX

PostPosted: Fri Jun 01, 2012 7:42 pm
by Hblade
For what ever reason, this makes my arrows shoot downward.

I don't know why but I have the most terrible game-editing luck in the existance of reality. Its BS

Re: My Arrows dont work right DX

PostPosted: Fri Jun 01, 2012 7:43 pm
by DarkParadox
Woops, my fault.
Sorry, use this:
Code: Select all
animpos=direction(xprevious, yprevious, x, y)/45;

Sorry 'bout that, accidentally setting angle, which is for directional_velocity.

Re: My Arrows dont work right DX

PostPosted: Fri Jun 01, 2012 7:48 pm
by Hblade
lol thanks. But why does it cause the arrow to glitch out?

Also: The arrows are still incorrect T.T

Oh and my arrows slide through the walls also. Again, an insanely mysterious thing. I have Physical Response set to repeat, but they slowly slide through the walls.

EDIT: Fixed the sliding problem.

Re: My Arrows dont work right DX

PostPosted: Fri Jun 01, 2012 7:51 pm
by DarkParadox
This code is just a test, more or less:
Code: Select all
int i=direction(xprevious, yprevious, x, y)/45;
animpos = i;


Well you have me stuck there. All this code does it take the current direction that your arrow is flying in and convert it to animpos.

If that doesn't work, try this:
Code: Select all
int i=(direction(xprevious, yprevious, x, y)/45)-1;
animpos = i;

Re: My Arrows dont work right DX

PostPosted: Fri Jun 01, 2012 7:53 pm
by Hblade
Maybe I need to change the animation of the arrows.. Relocate them or something.. o.O

Actually I got it to where it only shoots straight now.

Re: My Arrows dont work right DX

PostPosted: Fri Jun 01, 2012 8:34 pm
by skydereign
The problem is you have a weird starting frame. Usually rotation animations start from moving in the 0 angle direction (to the right). That means you have to use something like this (notice the 270-direction).
Code: Select all
animpos=(int)(nframes+((270-direction(xscreen, yscreen, xmouse, ymouse)+22.5)/45))%nframes;

Re: My Arrows dont work right DX

PostPosted: Fri Jun 01, 2012 8:45 pm
by Hblade
Thanks sky