doesn't work for me. The bullet moves directly upwards (the charatcter is fine though)
give me a min and ill post the example.
At 3/12/06 05:28 PM, Droneavp23 wrote: doesn't work for me. The bullet moves directly upwards (the charatcter is fine though)
give me a min and ill post the example.
ahh finally an answer to my problems!!!@@@###$$!
WOW awsome code Denvish!!! I was wondering though... I have tried changing # around in your script, but i can't sem to adapt it so it can only turn 180*. So u could put it at the bottom and shoot up. Can anyone help me with this, i can't get it to do it. Thanks
Simplest way would be to check the _ymouse against the MC._y
onClipEvent (mouseMove) {
if(_root._ymouse <this._y){
Xd =_root._xmouse-_x; //Get _x distance from gun to mouse
Yd =_root._ymouse-_y; //Get _y distance from gun to mouse
radAngle = Math.atan2(Yd, Xd); //Use atan2 to calculate the angle from gun to mouse
_rotation = int((radAngle*360 / (2*Math.PI))+90); //Use PI to calculate and set gun rotation
updateAfterEvent();
}
}
Thanks, Ya i though about doing it that way but im not the best at script so i didn't know how to word it. Thanks again
And then, run a for loop on your enemy MCs
onClipEvent (enterFrame) {
for(i=1000;i<1011;i++){
if (_root["b"+i].hitTest (this)) {
nextFrame();
}
}
}
If Im using this script on a turret that follows the player( like stays in place and the turret follows player) when i have the next frame in the movie clip have like an animation of an explotion, the explotion works and stuff, but the turret keeps on shooting at me(i have a script so it adimaticly shoots) What do i have to do to stop it shooting when its exploding and also remove it?
This is the bit that makes the bullets:
duplicateMovieClip("bullet", "b"+bc, bc);
If your 'normal' turret (ie, non-exploding) is on frame 1 of the turret MC, then just check the _currentframe of the turret MC before duplicating. This assumes that your turret MC has the Instance Name 'turret', and is on the _root:
if (_root.turret._currentframe<2){
duplicateMovieClip ("bullet", "b"+bc, bc);
}
And to remove your turret MC completely (you'll need to add this as an action on the final frame of the explosion)
_root.turret.swapDepths(999999);
_root.turret.removeMovieClip();
or just set it to invisible at the end of the explosion
_root.turret._visible=0;
How do you make multiple turrents? I made the instances different and also made MCs and change the code to each gun.
How can I make the gun move back about 5 to 10 degrees when I click ?
Just for a sort of recoil effect.
DANGIT!!!
I just cant get this to work... I put this on the MC instance named gun
onClipEvent (mouseMove) {
Xd =_root._xmouse-_x; //Get _x distance from gun to mouse
Yd =_root._ymouse-_y; //Get _y distance from gun to mouse
radAngle = Math.atan2(Yd, Xd); //Use atan2 to calculate the angle from gun to mouse
_rotation = int((radAngle*360 / (2*Math.PI))+90); //Use PI to calculate and set gun rotation
updateAfterEvent();
}
I put this on bullet
onClipEvent(load){
spd=20; //bullet speed
_x=_root.gun._x; //Move to gun _x
_y=_root.gun._y; //Move to gun _y
_rotation= _root.gun._rotation; //Point in same direction as gun
}
onClipEvent(enterFrame){
if(_name == "bullet"){
_x = -1000; //Move the original bullet MC offstage
}else{
//Run this movement code on all dupes
if (_rotation>180) {
_y += (spd*Math.cos( Math.PI/180*_rotation));
_x -= (spd*Math.sin( Math.PI/180*_rotation));
} else {
_y -= (spd*Math.cos (Math.PI/180*_rotation));
_x += (spd*Math.sin( Math.PI/180*_rotation));
}
//if(hitTest(_root.enemy)){ blahh; } Not going to address this here, check AS: Main for hitTest threads.
}
if(_x>Stage.width || _x<0 || _y<0 || _y>Stage.height){
//If off-stage, delete the dupe to save CPU
this.removeMovieClip();
}
}
And i put this on the frame of the movie all this stuff is in
var bc=1000; //bulletcount
_root.onMouseDown=function(){
bc++;
if(bc>1100){ bc=1000; } //Reset bulletcount
duplicateMovieClip("bullet", "b"+bc, bc); //Create dupe bullet
}
And it still wont work.. Im using flash 5 btw... why isnt it working?
Hello all...
bc=1000; //bulletcount
onMouseDown=function(){
bc++;
if(bc>1100){bc=1000;}
duplicateMovieClip("bullet", "b"+bc, bc);
with(_root["b"+bc]){
I'm rather confused on the above code...
For one, how can depth be specified for the duplicated MC's? Secondly, as I would like to fully understand the code before using it, in the part: ("bullet", "b"+bc, bc); what does the bc, bc part actually do? And finally, what instance names are the duplicates given? And how can this link to a hittest? I.e. I don't quite understand how one can make, as per a defence game, an enemy 'die' when the bullet MC come into contact with it?
I'm not very good at AS, so treat me like a novice in this:p
I don't want to just copy and paste codes... I'd rather gain a better understanding of AS in general:) which is why it would be great if anyone could help me, if it isn't too much trouble.
Thanks very much in advance...
James
Help plz?
When I shoot the gun, the bullets come out the side of my guy.
If I turn the MC to match the bullets, it's not pointing to the mouse!
What do I do? Don't call me a n00b, I'm just asking for some help. :)
Is there a way to make the turrent less accurate the futher the cursor is from the movie clip?
At 3/12/06 06:57 PM, Droneavp23 wrote:At 3/12/06 05:28 PM, Droneavp23 wrote: doesn't work for me. The bullet moves directly upwards (the charatcter is fine though)example
give me a min and ill post the example.
i broke your game :(
im having trouble with my hittest code.
it works in all my other stuff but not this.
help!
P.S. here is my code
onClipEvent (enterFrame) {
if (this.hitTest(_root.ENEMY)) {
_root.ENEMY.Play();
}
}
this just happen'd for me why??
Hey Denvish, i find that the first way to make the turret thing doesnt work for some reason.
Is there a way to control the rate of fire? so the bullets dont come out as fast?
How can I make the 'gun' appear inside a MC w/o getting an
error(with(object doesn't exist))?
It has to be on the main timeline with your code. So I get this...
Maybe its just because of the MC I used, but before i changed the code the mouse wouldnt follow it right, after i changed it, it started working. Maybe others have this problem?
Edited code ::
onClipEvent (mouseMove) {
Xd =_root._xmouse-_x; //Get _x distance from gun to mouse
Yd =_root._ymouse-_y; //Get _y distance from gun to mouse
radAngle = Math.atan2(Yd, Xd); //Use atan2 to calculate the angle from gun to mouse
_rotation = int((radAngle*360 / (2*Math.PI))+0); //Use PI to calculate and set gun rotation, I changed +90 to +0, so the angle would follow the mouse correctly, at least for me.
updateAfterEvent();
}
My turret doesn't shoot straight. Well, it does, but not if you move it while it is shooting. Anyways, just look it for yourself: My Turret . Can anyone Help me with that?
btw click thing turret if you want to see my turret, cuz theres to minigames in ther. Here's the link again, just in case:My Turret
Mine isnt working right, can someone tell me what I did wrong?
turret
Im using a border at the top and bottom of it, is there anyway to edit the code so the bullet goes behind the border??
Certain problems:
If you have applied all the correct script but nothing happens, check your instance names as they are important
If bullets are coming out of the side of your gun it is because your original movie clip is not facing up or may not be centered on that cross...
If the bullets come out from the center of your gun but are on top use this:
onClipEvent(load) {this.swapDepths(99999);}
If you want a gun to shoot only every three seconds then:
Add this to the gun
onClipEvent(load) {_root.timer = 0}
onClipEvent(enterFrame){_root.timer++}
Replace old shooting code with this:
var bc=1000; //bulletcount
_root.onMouseDown=function(){if(_root.time
r >= 72 //(my framerate x 3 )
){
bc++;
if(bc>1100){ bc=1000; } //Reset bulletcount
duplicateMovieClip("bullet", "b"+bc, bc); //Create dupe bullet
_root.timer = 0
}}
HitTesting.
if(hitTest(_root.player){
// do stuff
}
this was very helpfull.or would be if it worked.i tried boh and i read through the code trying to understand it.it doesnt work.dont know why it just doesnt work.message me.prefferably not profanely.