My Arrows dont work right DX

Non-platform specific questions.

My Arrows dont work right DX

Postby Hblade » Fri Jun 01, 2012 6:57 pm

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 1677 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
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: My Arrows dont work right DX

Postby DarkParadox » Fri Jun 01, 2012 7:29 pm

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.
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: My Arrows dont work right DX

Postby Hblade » Fri Jun 01, 2012 7:42 pm

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
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: My Arrows dont work right DX

Postby DarkParadox » Fri Jun 01, 2012 7:43 pm

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.
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: My Arrows dont work right DX

Postby Hblade » Fri Jun 01, 2012 7:48 pm

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.
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: My Arrows dont work right DX

Postby DarkParadox » Fri Jun 01, 2012 7:51 pm

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;
Last edited by DarkParadox on Fri Jun 01, 2012 7:53 pm, edited 1 time in total.
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: My Arrows dont work right DX

Postby Hblade » Fri Jun 01, 2012 7:53 pm

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.
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: My Arrows dont work right DX

Postby skydereign » Fri Jun 01, 2012 8:34 pm

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;
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: My Arrows dont work right DX

Postby Hblade » Fri Jun 01, 2012 8:45 pm

Thanks sky
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest