00:00
00:00
Newgrounds Background Image Theme

Bam76pixon just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Actionscript codes here!

391,393 Views | 7,981 Replies
New Topic

Response to Actionscript codes here! 2003-12-21 08:54:30


Well i'm not sure about the A.I etc.

For the random speed set a variable like so:-

speed = Math.random()*30

then when you are doing the key controls substitute the numer with speed like so:

if (Key.isDown(Key.UP)
this._y-=speed

change the 30 to whatever you like.

Response to Actionscript codes here! 2003-12-21 09:24:10


At 12/21/03 08:54 AM, Sulphent wrote: Well i'm not sure about the A.I etc.

For the random speed set a variable like so:-

speed = Math.random()*30

then when you are doing the key controls substitute the numer with speed like so:

if (Key.isDown(Key.UP)
this._y-=speed

change the 30 to whatever you like.

Thanks now i want tonow is it possible to make a code that makes something follow you but does it 3seconds after you did it.

I mean you drive a car then another car sets of and follows you, it would be grate if there was a script that could make the car ram you from behind or the side.

Response to Actionscript codes here! 2003-12-21 09:35:23


I can't think of a way at the moment but even a tweened enemy car could be used for it.

Response to Actionscript codes here! 2003-12-21 10:18:08


At 12/21/03 09:35 AM, Sulphent wrote: I can't think of a way at the moment but even a tweened enemy car could be used for it.

All i need is a way of sayin 1 second after you press "up" the car parked behind you starts and follows you. I could probly do the bit with the other car starting i sec after you but i cant make it so that the car follows you without making it into the same movie clip.

Is there a script so something follows something and then i could put something like if there is the instance of a car in the space the car following neads to be in then it waits for the other car to move before changing lanes.

Response to Actionscript codes here! 2003-12-21 10:49:22


thanks for all actionscrpts but i never use those :{

Response to Actionscript codes here! 2003-12-21 11:43:30


I can't find out how to make the animation of my character walking and his legs moving back and forth..Please help I need to know IN DETAIL because I'm a newb at this.

Response to Actionscript codes here! 2003-12-21 11:49:52


At 12/21/03 11:43 AM, Dylpic2008 wrote: I can't find out how to make the animation of my character walking and his legs moving back and forth..Please help I need to know IN DETAIL because I'm a newb at this.

You dont use action script for this so read the help files in flash and if you dont understand start your own thread.
P.S.dont call yourself a noob,wait for some-one else to do it for you.

Response to Actionscript codes here! 2003-12-21 11:52:42


Sorry for the double post but will some-one please reply to my last question not last post.Also is there a way of setting a random color for somthing.

Response to Actionscript codes here! 2003-12-21 13:14:02


Here is a tween for you mex of a car, i just did it basic the easing helps it slow down when it reaches its target.
here

Response to Actionscript codes here! 2003-12-21 13:20:18


At 12/21/03 01:14 PM, Sulphent wrote: Here is a tween for you mex of a car, i just did it basic the easing helps it slow down when it reaches its target.
here

That isnt what i meant. I meant for the computer car to follow you. To start of with both cars are parked on the side of the road then when you pull away and reach a certain point they pull out and follow you, i dont fknow how i would make it turn corners after you do and chage lanes after you.I could just make it all one movie clip but then when you change lane the other car might just go straight into another car which would be unrealistic.

Response to Actionscript codes here! 2003-12-21 13:24:21


[quote]Is there a script so something follows something and then i could put something like if there is the instance of a car in the space the car following neads to be in then it waits for the other car to move before changing lanes.
[/quote]
You are basically asking for a whole script here and i doubt anyone has this script anywhere

For a random colour try this:

Add to the actions of the thing you want a random colour:-

onClipEvent (enterFrame) {
colour = Math.round(Math.random(0x000000)*0xFFFFFF);
newcolour1 = new Color(this);
newcolour1.setRGB(colour);
}

Change the enterframe to whatever you want

Response to Actionscript codes here! 2003-12-21 13:30:45


Asking to script a Driver/GTA type game is a pretty hard task with the same intelligent AI as todays computers, especially with limited knowledge and even asking in this topic. You will have to use advanced action script like Math.cos and Math.sin ..etc.

Response to Actionscript codes here! 2003-12-21 13:36:39


At 12/21/03 01:24 PM, Sulphent wrote: [quote]Is there a script so something follows something and then i could put something like if there is the instance of a car in the space the car following neads to be in then it waits for the other car to move before changing lanes.
[/quote]
You are basically asking for a whole script here and i doubt anyone has this script anywhere

For a random colour try this:

Add to the actions of the thing you want a random colour:-

onClipEvent (enterFrame) {
colour = Math.round(Math.random(0x000000)*0xFFFFFF);
newcolour1 = new Color(this);
newcolour1.setRGB(colour);
}

Change the enterframe to whatever you want

I found this codebut i want the car to rotate as if it was follwing you, the following car is also extremly slow:

onClipEvent (enterframe) {
xdiff = (_root.player._x-_x);
ydiff = (_root.player._y-_y);
deg = Math.atan2(ydiff, xdiff);
_x += Math.cos(deg) * 1
_y += Math.sin(deg) * 1
}

Response to Actionscript codes here! 2003-12-21 13:58:32


Add this to the car you want to rotate:

onClipEvent (enterFrame) {
this._rotation = (Math.atan2(_root._car._y-this._y, _root._car._x-this._x))*(180/Math.PI);
}

exchange car to whatever the thing it points to is, it should work.

Response to Actionscript codes here! 2003-12-21 14:06:53


At 12/21/03 01:58 PM, Sulphent wrote: Add this to the car you want to rotate:

onClipEvent (enterFrame) {
this._rotation = (Math.atan2(_root._car._y-this._y, _root._car._x-this._x))*(180/Math.PI);
}

exchange car to whatever the thing it points to is, it should work.

I'm sorry to say this but it doesnt work

Response to Actionscript codes here! 2003-12-21 14:23:21


Sorry i checked and the way i do it doesn't work but only with the mouse cursor. Maybe someone with better trigonometry knowledge can help?

Response to Actionscript codes here! 2003-12-21 15:24:52


Mexxa:

Here's the basic idea of the script you're after... I've done one like this before to handle the homing missiles and 'smart' badguys in AB:Spermicide.

You need a function that tracks a waypoint, or a target. This is useful not only for having a badguy follow you, but also for having one move along a path, like a racetrack or something. What it does is check to see if it is off center from it's destination, and then turns towards it if it is. Here's a little snippet of the actual code I used:

function getMovement(){
if (Math.abs(targetTheta - _rotation) < 10 || Math.abs(targetTheta - _rotation) > 350){
_rotation = targetTheta;
turning = 0;
}
if (_rotation < targetTheta){
if(turning < turnSpeed_p) turning ++;
} else if (_rotation > targetTheta){
if(turning > -turnSpeed_p) turning --;
}
if(this.hitTest(targ.x, targ.y)){
getWayPoint();
}
pushVector(0, accel_p);
_rotation += turning;
}

in this example, turnSpeed_p was a property variable that determines how fast the clip turns. 'pushVector(0, accel_p)' was a function i wrote to add acceleration to the character based on the direction he was facing. You can remove that line and use your own script to handle acceleration. 'targetTheta' is a variable figured by another function:

function getPosition(){
if(Math.abs(_y - _parent.ship._y) < 200 && Math.abs(_x - _parent.ship._x) < 200){
targetVectorX = _parent.ship._x - _x;
targetVectorY = _y - _parent.ship._y;
} else {
targetVectorX = targ.x - _x;
targetVectorY = _y - targ.y;
}
hypVector = Math.sqrt(targetVectorX * targetVectorX + targetVectorY * targetVectorY);
targetThetaX = Math.asin(targetVectorX/hypVector)/RAD;
targetThetaY = Math.acos(targetVectorY/hypVector)/RAD;
if(targetVectorY < 0) targetTheta = 180 - targetThetaX;
else targetTheta = targetThetaX;
}

'targ' is an object that represents the target object. The reason i used x instead of _x is because it wasn't always a movie clip (sometimes, i used a custom waypoint object, with x and y properties. you can change them to _x and _y to work with an MC tho). RAD was just a constant i defined to convert from radians to degrees.

These functions just handle rotation, you'll need to add another to make the clip thrust forward, althought that's pretty simple, once you have the proper rotation. If you want the clip to wait a few seconds, start a counter variable going, and don't start running these functions until the counter hits a certain number.

If you need any more help with this script, or actually want working answers to other problems, AIM me at AngryBinary, or email angryBinary@hotmail.com

1010011010

Response to Actionscript codes here! 2003-12-21 15:42:46


What is the name of the target you use so that i can change it making the thing it follows called player.
Or if it isn't too much of a hassle or you dont like righting scripts out, could you right it out again without comments then could you right it out with only comments on where the name of the targets are or een better just change it and put the target as player.

P.S. does that make the object follow or catch the player cause if it cartches is it possible to put a hittest that makes it go backwards and the player go forwards. My only problem with the last bit is i can only make it go on one of the x and y not backwards from the angle.

Response to Actionscript codes here! 2003-12-21 15:44:25


oops i missed a bit on you r post now i understand which name to change but the rest would be helpful.

Response to Actionscript codes here! 2003-12-21 16:48:00


I see... well the basis of all that code was a vector based engine, using pantloads of physics. I can't really rewrite the code in a manner that you can actually use 'as-is', since alot of the code is dependant on the way the rest of the game code works. Here's a sum up...

To handle vector based motion for an object, here's the process your code should go thru:

Gather keyboard input, add acceleration/decceleration in X and Y directions to temp variables
External forces (i.e., collsions), also add to those temp variables.
Add temp variables to object's overall X and Y speeds.
Overall X and Y speeds are reduced by certain percentage to account for drag.
Zero out temp variables.

To make the object move according to it's rotation, here's the format:

_x += velocity * Math.sin(_rotation * Math.PI/180);
_y -= velocity * Math.cos(_rotation * Math.PI/180);

(assuming at 0 degrees rotation, the object is pointing straight up).

When i made my last post, i was kind've hoping you'd be able to pick up on the 'feel' of the code, to see how it was done. There's nothing i can post right now that you can use verbatim, but I'll try and get some tutorials up on the subject in the next couple of days at

http://raf.deadhounds.com

1010011010

Response to Actionscript codes here! 2003-12-21 16:51:21


At 12/21/03 03:42 PM, mexxa wrote: P.S. does that make the object follow or catch the player cause if it cartches is it possible to put a hittest that makes it go backwards and the player go forwards. My only problem with the last bit is i can only make it go on one of the x and y not backwards from the angle.

Oh yeah, and the code will make the object point towards the player and run right into it. What you can do is calculate the distance from the player and reduce the object's speed as it gets closer.

Incidentally, distance is:
xDist = _x - targ._x;
yDist = _y - targ._y;
distance = Math.sqrt(xDist*xDist + yDist*yDist);

Response to Actionscript codes here! 2003-12-21 17:10:18


I didnt quite understand thatr last post and i want to know why this code doesn't work.

onClipEvent (enterframe) {
xdiff = (_root.player._x-_x);
ydiff = (_root.player._y-_y);
deg = Math.atan2(ydiff, xdiff);
_x += Math.cos(deg) * 1
_y += Math.sin(deg) * 1
}
function getMovement(){
if (Math.abs(targetTheta - _rotation) < 10 || Math.abs(targetTheta - _rotation) > 350){
_rotation = targetTheta;
turning = 0;
}
if (_rotation < targetTheta){
if(turning < turnSpeed_p) turning ++;
} else if (_rotation > targetTheta){
if(turning > -turnSpeed_p) turning --;
}
if(this.hitTest(player.x, player.y)){
getWayPoint();
}
pushVector(0, accel_p);
_rotation += turning;
}
function getPosition(){
if(Math.abs(_y - _parent.ship._y) < 200 && Math.abs(_x - _parent.ship._x) < 200){
targetVectorX = _parent.ship._x - _x;
targetVectorY = _y - _parent.ship._y;
} else {
targetVectorX = player.x - _x;
targetVectorY = _y - player.y;
}
hypVector = Math.sqrt(targetVectorX * targetVectorX + targetVectorY * targetVectorY);
targetThetaX = Math.asin(targetVectorX/hypVector)/RAD;
targetThetaY = Math.acos(targetVectorY/hypVector)/RAD;
if(targetVectorY < 0) targetTheta = 180 - targetThetaX;
else targetTheta = targetThetaX;
}

Response to Actionscript codes here! 2003-12-22 10:43:39


All these actionscript codes are great, but can't someone make a tutorial (SWF) about them with diagrams and stuff? it'd be much easier for everyone (or at least me) to understand.

Response to Actionscript codes here! 2003-12-22 18:35:08


can anyone give me a script that saves the character and chooses a random opponent like in a fighting game?
I'm making a fighting game :P


That was a great post. Right Zach?

BBS Signature

Response to Actionscript codes here! 2003-12-22 21:07:20


Hey, i need to know how to make a actionscript where
when you move the mouse the crosshair goes with it like
in a shooter

Actionscript codes here!

Response to Actionscript codes here! 2003-12-22 21:13:27


At 12/22/03 09:07 PM, ryanryan wrote: Hey, i need to know how to make a actionscript where
when you move the mouse the crosshair goes with it like
in a shooter

For the smoothest action add this to the crosshair:

onClipEvent (mouseMove) {
this._x=_root._xmouse;
this._y=_root._ymouse;
updateAfterEvent();
}

Response to Actionscript codes here! 2003-12-22 21:35:56


I am trying to make it so that your controlling a guy but instead of when u push right the guy moves... i want it to be so that the backround moves left. And when your walking left i want it so that the backround moves right . thanks for your time!

Response to Actionscript codes here! 2003-12-22 21:38:31


Hey, i need to know how to make a actionscript where
when you move the mouse the crosshair goes with it like
in a shooter

Response to Actionscript codes here! 2003-12-22 21:41:21


Hey, i need to know how to make a actionscript where
when you move the mouse the crosshair goes with it like
in a shooter

Response to Actionscript codes here! 2003-12-22 21:51:42


which, behaviour do you have to put ur symbols in to
make the crosshair move with the mouse