bullet past mouse help

Talk about making games.

bullet past mouse help

Postby Oman » Mon Nov 06, 2006 2:19 am

Hi can someone explain to me in a simple way how to make your "player" actor create a bullet that goes toward the mouse, then goes past it and goes forever

can you please tell me in lamans terms, im new thx :D
"Beyond a wholesome discipline, be gentle with yourself." - Max Ehrmann
User avatar
Oman
 
Posts: 268
Joined: Tue Oct 31, 2006 4:00 am
Location: Somewhere out there...
Score: 6 Give a positive score

Postby sonicfire » Mon Nov 06, 2006 7:08 am

I would do it this way:

First, create a new actor, call it "crosshair" !
Use a little image like this:
Image
Go to Actor Control and choose Events: Add: Create Actor: Add Action: Follow Mouse to make it stick to your mouse.

Now create a new actor, the player. I used a simple pre-rotated tank (sorry for crappy graphics):
Image
Download BMP tank image strip here: http://www.prodyon-virtual-gear.com/tutorial/mytank.bmp


It contains 36 Images, one image all 10 degrees. Remember: It has to face to east on start and must be rotated counter-clockwise(!)
Now create again a new actor, call it "player" or something. Load up the tank-animation.

Now, we need some (simple) script.
Choose the player-actor, select Events: Add: Draw Actor: Script Editor and type in the following:
Code: Select all
double mouseangle = direction(xscreen,yscreen, xmouse, ymouse);
animpos = (mouseangle/360.0)*(nframes);


This little code makes sure the Tank will always rotate and face the mouse (e.g. a crosshair).

Some explanations: double mouseangle declares a new variable called "mouseangle" of type double precision (32 bit).

The function "direction" returns the direction between points (x1, y1) and (x2, y2) (in degrees, 0 to 360, from positive x axis, counterclockwise, in degrees). (This function returns double precision values).

x/yscreen and xy/mouse return xy coordinates of screen and mouse position. (AFAIK, x/yscreen return the "on screen" position of an actor).
then we finally use some maths to calculate the image to be shown at that very moment. (nframes returns the number of frames the actor has (animation images)).

Okay back to work!
If you would start the game now, the tank should always face the mouse / the crosshair.

Ok, now lets add the bullet:
Create a new actor, call it "bullet" or whatever you like.
Image

Download BMP bullet image strip here: http://www.prodyon-virtual-gear.com/tutorial/bullet.bmp

(I´ve made it red here that you can see it better in the game).

Place this bullet also somewhere on your "scene".
Again go into Actor Control. First, choose "Create at startup: No" (upper right corner). Now go into Events: Add: Draw Actor: Script Editor:
Code: Select all
animpos = (angle/360.0)*(nframes);

This will ensure that it will always face the direction it is traveling.

Next thing: Events: Add: Create Actor: Script Editor:
Code: Select all
angle = direction(x, y, crosshair.x, crosshair.y);
directional_velocity = 8;

Here we set the bullets angle so that i will face to the mouse(crosshair). Then we apply velocity to it so that it will fly in that direction.
All this is done ONCE. And only when it will be created.

Final step -> Go into Actor Control of your "player". Choose Events: Add: Key Down: (Use e.g. Space Key) Select Repeat: Disable (!). Then choose "Create Actor" as the action from the list.
Choose Actor: bullet and leave the rest as it is.

Done! Now you should be able to shoot bullets in the direction of the mouse (as much bullets as you want).

If i have made any mistakes here, hopefully someone can correct me please :D

Oh and by the way: You should also check if the bullets are "out of view" and then delete them to save resources / CPU. I leave that to you :wink:
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score

Postby Diana Kennedy » Mon Nov 06, 2006 8:03 am

Hey, that's cool. I never worked with that kind of thging, I will go ahead and try that out, just to learn that. 8)
User avatar
Diana Kennedy
 
Posts: 257
Joined: Wed Dec 07, 2005 12:34 am
Location: France, where Presidents who got shot in Texas do exile ;-)
Score: 0 Give a positive score

Postby Oman » Mon Nov 06, 2006 1:00 pm

Thx that was great and easy to understand. Ill give it a try.Oh by the way I didnt need the player actor or the bullet to turn but I know how to sort out that code. This is great the other forums didnt explain it correctly
GOOD JOB. :D :D :D :D
"Beyond a wholesome discipline, be gentle with yourself." - Max Ehrmann
User avatar
Oman
 
Posts: 268
Joined: Tue Oct 31, 2006 4:00 am
Location: Somewhere out there...
Score: 6 Give a positive score

Postby Oman » Mon Nov 06, 2006 11:03 pm

k i did that but when i press space the bullet is created but does not go towards my mouse. the bullet goes northwest on my screen can you help me wat did i do wrong :?
"Beyond a wholesome discipline, be gentle with yourself." - Max Ehrmann
User avatar
Oman
 
Posts: 268
Joined: Tue Oct 31, 2006 4:00 am
Location: Somewhere out there...
Score: 6 Give a positive score

Postby sonicfire » Tue Nov 07, 2006 8:58 am

@Oman: Mhh, can you send me the *.ged-file so that i can have a look? (But i´m still on trial version if that matters :))
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score

Postby Oman » Tue Nov 07, 2006 1:12 pm

could u tell me how i am only on the trial version to :?
"Beyond a wholesome discipline, be gentle with yourself." - Max Ehrmann
User avatar
Oman
 
Posts: 268
Joined: Tue Oct 31, 2006 4:00 am
Location: Somewhere out there...
Score: 6 Give a positive score

Postby sonicfire » Tue Nov 07, 2006 2:30 pm

Mhh you can perhaps just save the GED file to disk and then send it to me? That should be allowed? If you want you can PM me!
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score

Postby Oman » Tue Nov 07, 2006 10:46 pm

so how exactly do i pm u

im a nube i no :lol:
"Beyond a wholesome discipline, be gentle with yourself." - Max Ehrmann
User avatar
Oman
 
Posts: 268
Joined: Tue Oct 31, 2006 4:00 am
Location: Somewhere out there...
Score: 6 Give a positive score

Postby Oman » Sat Nov 18, 2006 2:38 am

ok i got it thx guys :D :D :D
"Beyond a wholesome discipline, be gentle with yourself." - Max Ehrmann
User avatar
Oman
 
Posts: 268
Joined: Tue Oct 31, 2006 4:00 am
Location: Somewhere out there...
Score: 6 Give a positive score

Postby J Maker » Mon Aug 13, 2007 3:45 pm

does anyone know how to make one actor turn so it will "still be facing" my player actor?
Some people believe Chuck Norris evolved from a dinosaur, the Chucknorisaurus.
----------------------------------------------------------------------------------
Chuck Norris doesn't sleep, he waits.
----------------------------------------------------------------------------------
Chuck Norris doesn't hunt, he kills.
----------------------------------------------------------------------------------
Chuck Norris once shot down a german fighter plane with his finger by yelling BANG!!!
----------------------------------------------------------------------------------
User avatar
J Maker
 
Posts: 177
Joined: Fri Jun 22, 2007 4:17 pm
Location: in the stick version of Hyrule
Score: 10 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron