|
-
[F8] Making a shooting game
Hello, i have a quick question.
I'm making a shooting game where you play as a man with a gun and the view is an eagle-eye view (you can only see the man's head). The gun has 8 angles (up, down, left, right and diagonals) and the 'bullet' which I want the gun to shoot is a straight line. I made it so the bullet is the same angle as the gun, but what I can't do is make it move in the right way i want it to move (ex. Move up when the gun is pointing up). Is there a code for this?
-
please help!! ive been wondering about this for a very long time
-
Total Universe Mod
Just make a gun clip and attach the bullet inside the clip. That way you only have to move the bullet forward on its local space. Then you can just rotate your gun clip to change the direction.
-
that would work, but lets say you point left and shoot. If you turn to the right, the bullet will turn too.
-
-
-
Modulator
Since your Bullet is moving, I'm assuming you've put in an element of speed. So lets see here:
Code:
vel = the speed you want the bullet to travel
if it's going:
Code:
UP
speedY = -vel;
speedX = 0;
DOWN
speedY = vel;
speedX = 0;
LEFT
speedY = 0;
speedX = -vel;
RIGHT
speedY = 0;
speedX = vel;
and so on and so forth (I hope you don't need me to explain the other 4 directions)
So, all you need to do is get the direction the man is facing:
Code:
function getFacing(){
you should be able to
figure something out
here, otherwise just email
me, or just say so.
return x, y; /*tell us whether x is going to be positive,
negative or zero, and do the same for y. That should send
our projectiles in the right direction.
*/
}
Now that you know which direction the man is facing, you should know what the x and y components of speed are going to be (in other words, is the bullet going left, right or neither. Is it going up, down or neither).
Now all you need to do is shoot the bullet in that direction e.g.
Actions for an MC named bullet_034, where vel = 5 or whatever, and the man is facing LEFT:
Code:
onClipEvent(load){//You don't really need this onClipEvent(load).
speedX = -vel;//When you create your bullet using attachMovie(),
speedY = 0;//You can tell it these properties anyways.
}
onClipEvent(enterFrame){
this._x += speedX;
this._y += speedY;
}
Hope this helps.
As a Gamer, you play by the rules.
As a Programmer, you play as God.
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|