Page 1 of 1

create bullet towards the mouse

PostPosted: Fri Sep 22, 2006 9:47 pm
by Zehper48
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

PostPosted: Fri Sep 22, 2006 10:53 pm
by DilloDude
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.

PostPosted: Sat Sep 23, 2006 1:45 am
by Zehper48
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

PostPosted: Sat Sep 23, 2006 2:45 am
by DilloDude
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);

PostPosted: Sat Sep 23, 2006 3:25 am
by Zehper48
When i did that my bullet was just created from were i clicked not from my guy

PostPosted: Sat Sep 23, 2006 6:34 am
by DilloDude
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.

PostPosted: Sat Sep 23, 2006 7:14 am
by pixelpoop
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.

PostPosted: Sat Sep 23, 2006 3:20 pm
by Zehper48
Thanks DilloDude i got it working now!
:D your very good at explaining

PostPosted: Mon Nov 06, 2006 1:58 am
by Oman
whenever i do this the bullet simpley goes slightly up and slightly over
like it goes toward the 10# on a clock :?