beginner question ("shooting arrows")

Non-platform specific questions.

beginner question ("shooting arrows")

Postby clickrush » Thu Nov 24, 2011 11:58 pm

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!
clickrush
 
Posts: 5
Joined: Tue Nov 22, 2011 2:20 pm
Score: 0 Give a positive score

Re: beginner question ("shooting arrows")

Postby skydereign » Fri Nov 25, 2011 1:00 am

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

Re: beginner question ("shooting arrows")

Postby clickrush » Fri Nov 25, 2011 12:10 pm

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!
Last edited by clickrush on Fri Nov 25, 2011 1:11 pm, edited 1 time in total.
clickrush
 
Posts: 5
Joined: Tue Nov 22, 2011 2:20 pm
Score: 0 Give a positive score

Re: beginner question ("shooting arrows")

Postby foleyjo » Fri Nov 25, 2011 12:59 pm

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)
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: beginner question ("shooting arrows")

Postby clickrush » Fri Nov 25, 2011 1:14 pm

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!
clickrush
 
Posts: 5
Joined: Tue Nov 22, 2011 2:20 pm
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest