Results 1 to 11 of 11
Thread: tank shooting/moving
-
February 16th, 2005, 05:24 PM #1
tank shooting/moving
ok! So I have a rotating barrel (or what it's called), and the basic for the shooting. But I can't get the tank to move, because then the barrel wont rotate/shoot. The barrel and the body of the tank are seperate MC's.
My question: How do I make the tank move at the same time as you can move the barrel?
Then I have a few more questions, but this is the most urgent.
Hope you understand what I am trying to say
-
February 16th, 2005, 06:37 PM #2
Instead of using else if's to test your keyPresses... I would suggest using on if statements.
Code:_root.onEnterFrame = function() { if(Key.isDown(Key.DOWN)) { move tank down; } if(Key.isDown(Key.UP)) { move tank up; } if(Key.isDown(Key.LEFT)) { move tank left; } if(Key.isDown(Key.RIGHT)) { move tank right; } if(Key.isDown(Key.SPACE)) { have tank shoot; } // and so on and so forth.... }aiMarz : v. 11.34c - Current Version
-
February 17th, 2005, 02:35 AM #3
yeah, I've tried that, but I want the barrel to move after the mouse.
-
February 17th, 2005, 03:42 AM #4
And your point is? As long as you have an if statement with the arrow keys, putting in a mouse location and pointing the barrel towards the mouse is easy.
._xmouse and ._ymouse is the location of your mouse's pointer on the screen. Use those along qwith trigonometry and put the results in the onEnterFrame. And you'll be fine.aiMarz : v. 11.34c - Current Version
-
February 17th, 2005, 05:17 AM #5
Yes... But I can't make the tank move at the same time as the barrel is moving...
The barrel is one MC and the tank is one. How do I attach them to eachother so that the mouse pointing thing wticks with the tank.... It's hard to explain, when I get home, I can post the .fla
-
February 17th, 2005, 05:51 AM #6
Simple enough.... The base of each MC willl stay together. Your barrel should pivot around one point and that point should be the x and y coordinates of your tank + or - some pixels here and there. So everytime the player moves the tank, he also moves the turret.
Then you will only have to worry which direction the barrel is facing. Which if you draw it correctly, can be determined by the ._rotation property.Code:// Case in point if(Key.isDown(Key.DOWN)) { // move tank down } // blah blah blah.... turret._x = tank._x; turret._y = tank._y;
aiMarz : v. 11.34c - Current Version
-
February 21st, 2005, 01:04 AM #7
You can also make a function that rotates MC's to the mouse or wuteva else u want them to:
function pointAt(ob, x, y,offset){
var dx = x - ob._x;
var dy = y = ob._y
var dist = Math.sqrt(dx*dx+dy*dy)
var angle;
if(dy<0){
angle = Math.PI*2-Math.acos(dx/dist);
} else {
angle = Math.acos(dx/dist);
}
ob._rotation = angle*180/Math.PI+offset;
}
put this in the first frame of your movie, then in the tank barrel add:
onClipEvent(enterFrame){
_root.pointAt(this, _root._xmouse, _root._ymouse, *wuteva the offset is*);
}
*offset depends on how you drew tank barrel, for example, if tank rotation is off by 90 degrees, add 90 in that field*"An optomist says a glass is half full.
A pessimist says the glass is half empty, and I may have bowel cancer"
-Kids in The Hall-
-
February 21st, 2005, 08:22 AM #8
yeah, thanks, but I already have the rotation for the barrel and the movement for the tank... It's just that the barrel and the tank are seperate MC's, so the tank moves, but the barrel stays
I'm looking for a way to make the Barrel MC and the tank MC stuck to eachother... If you understand what I mean... Thanks for the help though
-
February 21st, 2005, 11:52 AM #9
add in on ur tank
if(key.isDown(Down)){
tank._y+= wuteva
turret._y+=wuteva
}
and do that for all ur movements. I had the same prob, the call to put the turret on the tank comes after the call to move it, which causes the turret to lag. If thats wut ur talking about"An optomist says a glass is half full.
A pessimist says the glass is half empty, and I may have bowel cancer"
-Kids in The Hall-
-
February 21st, 2005, 03:10 PM #10
I would have personally put the turret movieclip inside of the tank movieclip.
_root.tank.turret._rotation = blah blah;
That will only rotate the turret, but if you were to do this :
_root.tank._x += 5;
It would move the tank and the turret.aiMarz : v. 11.34c - Current Version
-
February 22nd, 2005, 10:19 AM #11
i use that code for moving my character marz, but when i say move and it palys animation_1 and press attack and it plays fight animation, it gets confused? is there a way to specify to do the attack one above all the others?
and when pressing multiple keys it has issues with my key releaseing code to stop the anmations playing. could you post the code for key ups that you would use?
Similar Threads
-
AS 1.0 FMX04 Tank game...
By Pneumonic in forum Game/AI ProgrammingReplies: 5Last Post: November 30th, 2004, 01:22 PM -
Tank Game
By benji2004 in forum Flash IDEReplies: 0Last Post: September 21st, 2004, 03:26 PM -
Tank Wars!
By idolthoughts in forum User Interface / Design DiscussionReplies: 20Last Post: August 8th, 2004, 01:16 AM -
Help with Tank game AI
By Lomadrian in forum Game/AI ProgrammingReplies: 1Last Post: August 4th, 2004, 07:57 AM -
Master64 - Tank Wars
By Johnny64 in forum Flash Game ContestReplies: 3Last Post: July 10th, 2004, 03:08 AM

Reply With Quote

Bookmarks