Click on the movie to activate it
Use the arrow keys to move the tank and the z and x keys to rotate the turret.
Example:
Base.png

turret.png
![]()
Step.1
save the images above, import the base.png into swishmax 4, group it as a movieclip and name it base.
import the turret.png and group it as a movieclip, name it as turret, center the transform point for both images.
now group both the movieclips together as a new movieclip and name it tank.
add the following script to the tank movieclip.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | onSelfEvent (enterFrame) { if (Key.isDown(Key.UP)) { speed = 3; }else{ speed = 0 } if (Key.isDown(Key.DOWN)) { speed = -3; } if (Key.isDown(Key.LEFT)) { _rotation -= 2; } if (Key.isDown(Key.RIGHT)) { _rotation += 2; } if (Key.isDown(Key.Z)) { turret._rotation-=2; } if (Key.isDown(Key.x)) { turret._rotation+=2; } speed *= .98; x = Math.sin(_rotation*(Math.PI/180))*speed; y = Math.cos(_rotation*(Math.PI/180))*speed*-1; _x += x; _y += y; // hi = Math.sin(_rotation * 1.745329E-002) * 30; ip = Math.cos(_rotation * 1.745329E-002) * 30; _root.k1 = hi; _root.k2 = ip; if (Key.isDown(Key.UP)) { _root.drawing.lineStyle(6, 000000, 1.5); // line thickness, rgb, alpha } else { _root.drawing.lineStyle(6, 000000, 1.5); // line thickness, rgb, alpha } _root.drawing.moveTo(iks, ips); _root.drawing.lineTo(_x - ip, _y - hi); _root.drawing.moveTo(iks2, ips2); _root.drawing.lineTo(_x + ip, _y + hi); iks = _x - ip; ips = _y - hi; iks2 = _x + ip; ips2 = _y + hi; } onSelfEvent (load) { _root.createEmptyMovieClip("drawing", 1); this.swapDepths(_root.drawing); _root.clearBtn.swapDepths(this); hi = Math.sin(_rotation * 1.745329E-002) * 30; ip = Math.cos(_rotation * 1.745329E-002) * 30; iks = _x - ip; ips = _y - hi; iks2 = _x + ip; ips2 = _y + hi; } |





2 comments
pitrsman
October 2, 2012 at 3:17 pm (UTC 1) Link to this comment
Excelent base for vehicle movement, thank you. Just one thing, please fix backward movement: speed = 3, to -3 and rename movieclip turret to gun and then is everything working perfect. Sorry for this. Bye
Craig Lowe
October 27, 2012 at 8:47 am (UTC 1) Link to this comment
Thanks for the heads up, all amended
.