Be a Supporter!

As: Help!!!

  • 344 Views
  • 3 Replies
New Topic Respond to this Topic
Re2deemer
Re2deemer
  • Member since: Nov. 3, 2005
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
As: Help!!! 2006-06-03 05:57:36 Reply

onClipEvent (enterFrame) {
if (Key.isDown(87)) {
speed += 5;
}
if (Key.isDown(83)) {
speed -= 5;
}
if (Math.abs(speed)>20) {
speed *= .7;
}
if (Key.isDown(65)) {
_rotation -= 15;
}
if (Key.isDown(68)) {
_rotation += 15;
}
speed *= .60;
x = Math.sin(_rotation*(Math.PI/180))*speed;
y = Math.cos(_rotation*(Math.PI/180))*speed*-1
;
if (!_root.land.hitTest(_x+x, _y+y, true)) {
_x += x;
_y += y;
} else {
speed *= -.8;
}
}

This code has been retrieved from a tutorial here in Newgrounds. In some reason the code does not work. The MC does rotate, but it doesn't move fovard or backward.

PS. I replaced the arrow keys with WASD buttons, but the problem existed before the replacement.


BBS Signature
GuyWithHisComp
GuyWithHisComp
  • Member since: Nov. 10, 2005
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Response to As: Help!!! 2006-06-03 06:02:00 Reply

you need to declare the value of speed before you can change it. place this code before your code:
onClipEvent(load){
var speed:Number = 0;
}


BBS Signature
CrustySheet
CrustySheet
  • Member since: May. 3, 2006
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to As: Help!!! 2006-06-03 06:02:03 Reply

onClipEvent(load){
speed= 5;
}

onClipEvent (enterFrame) {
if (Key.isDown(87)) {
_x +=speed;
}
if (Key.isDown(83)) {
_x -=speed;
}
if (Math.abs(speed)>20) {
speed *= .7;
}
if (Key.isDown(65)) {
_rotation -= 15;
}
if (Key.isDown(68)) {
_rotation += 15;
}

Re2deemer
Re2deemer
  • Member since: Nov. 3, 2005
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to As: Help!!! 2006-06-03 07:11:04 Reply

thx, snail!!!


BBS Signature