Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 1.0 (and below)

Thread Tools Rate Thread Display Modes
Old 05-05-2005, 12:05 AM   #1
Registered User
Join Date: May 2005
Posts: 1
Unhappy How to control a movie clip's motion with keys while having it point at the mouse?

I'm scripting a top-down game here, and it's pretty much my first major Flash project and I'm sort of stuck. My AS appears to be all sound, so I can't figure out why this doesn't work.
Below is the code that is on my player character.
ActionScript Code:
// The 'onClipEvent' header is to make sure everything is executed on each frame so that the game always works onClipEvent(enterFrame){     // Pointing script for the object     this.pointAt(this._parent._xmouse, this._parent._ymouse);     // Movement keys     if (Key.isDown( 65 )) {         this._x = this._x - movement;     }     if (Key.isDown( 87 )) {         this._y = this._y + movement;     }     if (Key.isDown( 83 )) {         this._y = this._y - movement;     }     if (Key.isDown( 68 )) {         this._x = this._y + movement;     }     // End movement keys }
This is the code that defines variables and makes the pointAt script possible, or maybe it's unnecessary...
ActionScript Code:
// Point at cursor script MovieClip.prototype.pointAt = function(x,y) {   var dx = x - this._x;         // distance to other object on x-axis   var dy = y - this._y;         // distance on y-axis   var dist = Math.sqrt(dx*dx + dy*dy); // true distance (using Pythagorean theorem)   var angle;   // figure out angle in radians (0- 2*PI)   if (dy <0)     angle = Math.PI*2-Math.acos(dx/dist);   else     angle = Math.acos(dx/dist);   // convert to rotation value (angle in degrees or 0-360)   this._rotation = angle*180/Math.PI; } // End point at cursor script //---------------------------------------------------------------------------------------------- // Variables // Player Variables movement=1 // Enviromental Variables (Wind, Gravity, Drag, etc.) FrisbeeSpeed=8 gravity=0.7 drag=0.8 wind=0.4

And of course, the code for my crosshair
ActionScript Code:
onClipEvent (enterFrame) {     this._x = _root._xmouse;     this._y = _root._ymouse;     Mouse.hide(); }

As you can see, I tend to document my code pretty well so others can use it if they need to. But what my problem is is that when I press D - No other key, just D - my player movie clip teleports to the center of the movie and won't move. My other controls don't work either. Is there something missing here? Or is my coding just wrong? Please help!
psyflame is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

All times are GMT. The time now is 05:32 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.