Page 1 of 1

beginner question ("shooting arrows")

PostPosted: Thu Nov 24, 2011 11:58 pm
by clickrush
hi everyone,

I (complete newbie) have a rather simple problem I'am stuck with (no programming experience).

I've made sth like a top-down shooter where you can shoot arrows. Now the arrow checks in which direction it's shooting and chooses one of 8 animations for that.
The problem is: When I'am shooting them arrows fast enough then the allready shot arrows copy the animation of the newly shot one's. So when the shooter turns around
fast enough then the outer arrows have wrong animations. I hope you get what I mean.

I use "create actor" on click and a script that chooses animation and angle according to mouse relative to creator on creation of the arrow.

Thx for any help/tips in advance!

Re: beginner question ("shooting arrows")

PostPosted: Fri Nov 25, 2011 1:00 am
by skydereign
Can you post the code you are using? The problem sounds like one you would come across using draw actor, but you say you use create actor. Another possibility is if you used "arrow" or whatever the arrow's name is, instead of "Event Actor".

Re: beginner question ("shooting arrows")

PostPosted: Fri Nov 25, 2011 12:10 pm
by clickrush
on create actor:

edit: aim is the direction between mouse and the shooter (i also used aim when changing the shooter animation according to his "aiming")
edit2: draw actor obv makes it worse (then the arrow even changes angle). is switching the event_actor into "bullet" (=arrow) even possible? when i choose the create actor event then it doesnt give me the choice.
edit3: I dont understand why the arrow never changes his angle (direction player->mouse which is stored in "aim") but he does change his animation...

Code: Select all
//shoots bullet into direction of mouse
directional_velocity=20;
angle=aim;


//return arrow animation direction
if (aim<22.5)
{
arrowdir=1;
}
else if (aim<67.5)
{
arrowdir=2;
}
else if (aim<112.5)
{
arrowdir=3;
}
else if (aim<157.5)
{
arrowdir=4;
}
else if (aim<202.5)
{
arrowdir=5;
}
else if (aim<247.5)
{
arrowdir=6;
}
else if (aim<292.5)
{
arrowdir=7;
}
else if (aim<337.5)
{
arrowdir=8;
}
else
{
arrowdir=1;
}

// change animation according to arrow direction
if (arrowdir==1)
{
    ChangeAnimation("bullet", "arrowrr", FORWARD);
}
if (arrowdir==2)
{
    ChangeAnimation("bullet", "arrowur", FORWARD);
}
if (arrowdir==3)
{
    ChangeAnimation("bullet", "arrowup", FORWARD);
}
if (arrowdir==4)
{
    ChangeAnimation("bullet", "arrowul", FORWARD);
}
if (arrowdir==5)
{
    ChangeAnimation("bullet", "arrowll", FORWARD);
}
if (arrowdir==6)
{
    ChangeAnimation("bullet", "arrowdl", FORWARD);
}
if (arrowdir==7)
{
    ChangeAnimation("bullet", "arrowdown", FORWARD);
}
if (arrowdir==8)
{
    ChangeAnimation("bullet", "arrowdr", FORWARD);
}


EDIT4 SOLUTION:
your comment about event actor vs "bullet" made me think again. I changed ChangeAnimation("bullet".... into ChangeAnimation("Event Actor"... and it works fine!

I thought so far that "Event Actor" and "actorname" is the same thing, which obv. it isn't! It seems that "Event Actor" is some kind of part of "bullet", that is refered to when an event happens to "bullet" (sry about my english...)

Figuring out things like that cost me ours of iteration so far (because again, I have no programming experience, I'am learning on the fly here with many tabs open about C language etc. :) ).

Another example of me being stuck was the MoveTo action. I thought the X and Y values are some kind of fix coordinates until I realised they are vectors relative to sth. My intention was make the shooter slow down when shooting. So I figured I had to store the moveto action then order a new moveto with slower velocity when the shooting animation began and again one with a normal velocity when it finished. The first time I tried this, the shooter walked too far. After some tests I figured that the additional distance was exactly the same as the distance between the start of the move and last shooting action. Only then I realized iam working with vectors and had calculate and substract the vector between the start of the move and the last shooting action.

So if you can think of any similar thing or a tutorial/site I should visit then pls let me know. Thx for reading and helping!

Re: beginner question ("shooting arrows")

PostPosted: Fri Nov 25, 2011 12:59 pm
by foleyjo
Not a solution to your issue but a method for making the code a bit easier on the eyes.
First make sure the anim images are all in the correct order and then change the changeanimation lines to

Code: Select all
ChangeAnimation("bullet", getAnimName(arrowdir),forward)

Re: beginner question ("shooting arrows")

PostPosted: Fri Nov 25, 2011 1:14 pm
by clickrush
Thx alot. I'am in need of tricks like that. My code is very chatoic :).

I figured out the solution because skydereign made me think of the right things:
your comment about event actor vs "bullet" made me think again. I changed ChangeAnimation("bullet".... into ChangeAnimation("Event Actor"... and it works fine!

I thought so far that "Event Actor" and "actorname" is the same thing, which obv. it isn't! It seems that "Event Actor" is some kind of part of "bullet", that is refered to when an event happens to "bullet" (sry about my english...)

Figuring out things like that cost me ours of iteration so far (because again, I have no programming experience, I'am learning on the fly here with many tabs open about C language etc. :) ).

Another example of me being stuck was the MoveTo action. I thought the X and Y values are some kind of fix coordinates until I realised they are vectors relative to sth. My intention was make the shooter slow down when shooting. So I figured I had to store the moveto action then order a new moveto with slower velocity when the shooting animation began and again one with a normal velocity when it finished. The first time I tried this, the shooter walked too far. After some tests I figured that the additional distance was exactly the same as the distance between the start of the move and last shooting action. Only then I realized iam working with vectors and had to calculate and substract the vector between the start of the move and the last shooting action.
here my finished code so you can imagine it better:
Code: Select all
MoveTo("player", xwalking-xscreen+xarcher, ywalking-yscreen+yarcher, aspeed, "player", "");

x/ywalking are the stored x/ymouse vectors when issuing the moveto action. x/yarcher are the stored x/yscreen vectors when the last shooting happened.

So if you can think of any similar thing or a tutorial/site I should visit then pls let me know. Thx for reading and helping!