create bullet towards the mouse

Non-platform specific questions.

create bullet towards the mouse

Postby Zehper48 » Fri Sep 22, 2006 9:47 pm

Hey Everybody, I would like my actor to create a bullet in the direction the mouse is pointing But i dont want the bullet to keep following the mouse. Like when i click left mouse button my actor creates the bullet going to the mouse.
If somebody could give me a code or help or something it would be greatly apreciated thanks :D
I like score
User avatar
Zehper48
 
Posts: 241
Joined: Sun Jun 11, 2006 1:34 am
Location: Advanced Noob
Score: 4 Give a positive score

Postby DilloDude » Fri Sep 22, 2006 10:53 pm

Just use
Code: Select all
angle = direction(xscreen, yscreen, xmouse, ymouse);

on bullet's create actor.
If you have a rotation animation and you want the bullet to point in the right direction, also add
Code: Select all
animpos = (angle / 360) * nframes;

for the standard animation starting pointing to the right, and rotating counter-clock-wise.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby Zehper48 » Sat Sep 23, 2006 1:45 am

how do i make it wear if i click anywere on the screen my guy creates the bullet. i dont have a rotation animation its just a ball. i want the ball to go to wear the mouse was at a velocity of 10. i think im not doing something with the code that you gave me
I like score
User avatar
Zehper48
 
Posts: 241
Joined: Sun Jun 11, 2006 1:34 am
Location: Advanced Noob
Score: 4 Give a positive score

Postby DilloDude » Sat Sep 23, 2006 2:45 am

First, you need an actor to catch mouse clicks. Either use a filled region or an actor that follows the mouse using the FollowMouse function. If it follows the mouse, it's a good idea to make it a largish circle or something. Then set visibility state to DONT_DRAW_ONLY, and you can change the cursor if you like. Now, you have two options: right-click on the sensor actor, say add new activation event, set it to mousebuttondown->left mouse button, and select your player as the receiving actor, or ad a mousebutton down script editor event with
Code: Select all
sendActivationEvent("Player");

Now on your player actor, add a new event, Activation Event, from your mouse sensor, and use a CreateActor to create a bullet. On the bullet's create actor event, say
Code: Select all
directional_velocity = 10;//adjust value to your preference
angle = direction(xscreen, yscreen, xmouse, ymouse);
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby Zehper48 » Sat Sep 23, 2006 3:25 am

When i did that my bullet was just created from were i clicked not from my guy
I like score
User avatar
Zehper48
 
Posts: 241
Joined: Sun Jun 11, 2006 1:34 am
Location: Advanced Noob
Score: 4 Give a positive score

Postby DilloDude » Sat Sep 23, 2006 6:34 am

You need to have the guy receive the activation event and create the bullet, rather than have the actor that receives the mousebuttondown event create it.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby pixelpoop » Sat Sep 23, 2006 7:14 am

for an example look at the abuse demo. you'll have to sort through a bunch of other code to see what you are aiming for though.
User avatar
pixelpoop
 
Posts: 276
Joined: Tue Aug 29, 2006 9:32 pm
Score: 28 Give a positive score

Postby Zehper48 » Sat Sep 23, 2006 3:20 pm

Thanks DilloDude i got it working now!
:D your very good at explaining
I like score
User avatar
Zehper48
 
Posts: 241
Joined: Sun Jun 11, 2006 1:34 am
Location: Advanced Noob
Score: 4 Give a positive score

Postby Oman » Mon Nov 06, 2006 1:58 am

whenever i do this the bullet simpley goes slightly up and slightly over
like it goes toward the 10# on a clock :?
"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


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest