Character Movement
Hi,
I'm putting together a simple game for a client and I've come across a small problem.
I have a simple character, which moves upon key presses (cursor keys).
This is the code I have so far. (keyspeed is defined as 5)
onClipEvent (enterFrame) { if (Key.isDown(37)) { _x=_x-keyspeed; } if (Key.isDown(38)) { _y=_y-keyspeed; } if (Key.isDown(39)) { _x=_x+keyspeed; } if (Key.isDown(40)) { _y=_y+keyspeed; } }
This works fine. What I need to happen now is, say, when key 37 (left) is pressed, the character (movieclip called character) should goto and play a new part which shows the character walking left. When key 39 (right) is pressed, character should goto and play a new part which shows the character walking right. And so on. If no key is pressed, then I want the character to play another part of it's movieclip where the character stand still This is the new code I therefore have:
onClipEvent (enterFrame) { if (Key.isDown(37)) { _x=_x-keyspeed; _root.character.gotoAndStop("walkleft"); } else if (Key.isDown(38)) { _y=_y-keyspeed; _root.character.gotoAndStop("walkup"); } else if (Key.isDown(39)) { _x=_x+keyspeed; _root.character.gotoAndStop("walkright"); } else if (Key.isDown(40)) { _y=_y+keyspeed; _root.character.gotoAndStop("walkdown"); } } else { _root.character.gotoAndStop("standstill"); } }
But this doesn't work. The character won't jump to the designated frame labels.
Can anyone suggest why this is happening? I'm know is something really, really simple and I'm going mad. I have every other aspect of the game working (health, collectables, hittest etc) just not this damn simple thing.
Any help would be gratefully received.
Thanks In Advance
Steve
FlashKit > Flash Help > Flash ActionScript
Posted on: 04-10-2006, 05:34 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Help With Character Movement
what I am looking for is some help with making my Character
face in the right Direction. I not to sure were to start
so if you could take a look at this fla it would probible help
http://www.mac-10.net/man1.fla
hope you can help
mac
Character Movement...
Ok, ive got 4 diff. animations of my character, each going in the respective direction. How can I change the animation for the correct direction he is heading in.. IE, If left key pressed: Left_run animation is played. This is the code I have so far for general movement:
onClipEvent (load) {
inc = 10;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x += inc;
}
if (Key.isDown(Key.LEFT)) {
this._x -= inc;
}
if (Key.isDown(Key.UP)) {
this._y -= inc;
}
if (Key.isDown(Key.DOWN)) {
this._y += inc;
}
}
onClipEvent (load) {
}
thanks guys,
Tman
Character Movement
I am currently making a game where you controll a character with you arrow keys you know the usual thing.
Well I was wondering if there is a better way to stop the movement if you encounter a wall or a object.
//this is my charachter controll(it's a semi 3d perspective so thats why the x is larger then the y//
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
_root.slide._x = _root.slide._x+5.5;
}
if (Key.isDown(Key.LEFT)) {
_root.slide._x = _root.slide._x-5.5;
}
if (Key.isDown(Key.UP)) {
_root.slide._y = _root.slide._y-4;
}
if (Key.isDown(Key.DOWN)) {
_root.slide._y = _root.slide._y+4;
}
}
//this is the code in each object that stops the movement(slide is the character)//
onClipEvent (enterFrame) {
/:status = hitTest(_root.slide._x, _root.slide._y, true);
}
onClipEvent (enterFrame) {
if (/:status==true&&Key.isDown(Key.RIGHT)) {
_root.slide._x = _root.slide._x-5.5;
}
if (/:status==true&&Key.isDown(Key.LEFT)) {
_root.slide._x = _root.slide._x+5.5;
}
if (/:status==true&&Key.isDown(Key.UP)) {
_root.slide._y = _root.slide._y+4;
}
if (/:status==true&&Key.isDown(Key.DOWN)) {
_root.slide._y = _root.slide._y-4;
}
}
Well that works fine but it's not that smooth with that code in each object.
Character Movement
Is there any way to detect if both the up key and left key are down? I am making an animation where a character walks and I want to have a frame for each direction up, down and right and left is no problem but to detect if both the up and left keys are down doesn't work! Any suggestions?
Character Movement? Ne1 Pls
Hi,
I am really strugglin to find a solution.. ne help is much appreciated. I am using MX, I am trying to make a man walk around the screen using the arrow keys from a birdseye view. That all works but when no keys are pressed i would like the script to jump to a frame where there is a movie clip where the character looks up as if to say (i'm waiting) i can get this to work by telling the script to jump to frame label stop. The problem with this is that the stop label animation only faces one way so (say the stop animation movieclip is facing up) if you are walking down and then release the down key, the clip flicks to the up position and looks messy. How can i get the stop movie clip to face the way of the last key press?
I hope i have made myself clear?
here is the script i am using which is attached to the 'man' movieclip
onClipEvent (load) {
moveSpeed = 10;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
_root.man.gotoAndStop("right");
this._x += moveSpeed;
} else if (Key.isDown(Key.LEFT)) {
_root.man.gotoAndStop("left");
this._x -= moveSpeed;
} else if (Key.isDown(Key.DOWN)) {
_root.man.gotoAndStop("down");
this._y += moveSpeed;
} else if (Key.isDown(Key.UP)) {
_root.man.gotoAndStop("up");
this._y -= moveSpeed;
} else {
_root.man.gotoAndStop ("stop");
}
}
Character Movement
I have a character that has a walking animation and I want that animation to play when the person presses left or right, along with ther character moving left or right this is what i have so far
__________________________________________
onClipEvent (enterFrame) {
speed = 5;
if (Key.isDown(Key.LEFT)) {
_x -= speed;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
}
}
on (keyPress "<Left>") {
_root.character.gotoAndPlay(6);
}
on (keyPress "<Right>") {
_root.character.gotoAndPlay(2);
}
___________________________________
this works, the character moves from left to right and the walking animation goes, but after a while the walking animation seems to repeat the first frame or two, also how would i make it stop when he button isnt being pressed
Character Movement
Hey ive started on a little flash game, its just a 2D top down thing.
What im trying to do is being able to rotate and then walk in that direction.
I had up, down, left, right turning before but its not really what im after.
I have the rotation stuff working but it never moves in the exact direction your facing its normaly like 20 degrees off.
I know why this is but not how to fix it, and to fix it I need a different method of calculating the next x,y position.
Ok and the other thing to do with this is the hit detection to go with it, it needs to then calculate 3 points for left center and right positions of the character.
Character Movement
hie.. i'm still very new in flash...especially actionscript. I would like to ask about the actionscript. Currently, I'm developing an adventure game. I have design several characters already. How can I make them react to the key I press? (up - move up). I had created several layers of different movement so that it will look like a real walking. I really need your help, guys. Thanks~
Character Movement
should i combine all the movements using different layers in a single .fla or combine all of them in different frames in a single layer? please help...
Character Movement
Here is how i coded for the character to move:
-----------------------------------------------------------------
1.am clear how i want to navigate the character to the desired spot
2.am also able to initialise the walk animation once clicked.
3.my problem is am not able to stop walking animation of the guy once he reached the spot.
-----------------------------------------------------------------------------------------------
onClipEvent(load){
_x=0;
_y=200;
}
onClipEvent(mouseDown){
//jump to clicked location
targetx=_root._xmouse;
_root.man_mc.man.gotoAndStop("right")
if(distx==_root._xmouse){
_root.man_mc.man.gotoAndStop("idle")
}
}
onClipEvent(enterFrame){
//the amount of distance to travel to click spot
distx=targetx-_x
//speed and easing factor character to reach the spot
movex=distx/20
_x+=movex;
}
-----------------------------------------------------------------------------------------------------
and more over i need to make him walk facing left side, when he need to
travel left side from his current position.
I have attached the file for your reference.
thanks in advance.
da_hammer
Help With Character Movement
Sorry if this is in the wrong catagory. This is my first time to the forums here.
I've been searching all around the web, trying to find help for something that seemed so simple; the action code for making a character jump.
I'm able to move the character left and right just fine, but I can't figure out exactly how to make it jump up into the air.
If you could help, I'd greatly appreciate it.
Character Movement
Hey guys I am fairly new to flash and I have been having a bit of trouble with a game I am trying to make so I need a little help.
What I am trying to do is to get the little character in the middle of my screen to move in different directions using the arrow keys. I have gone through many different tutorials on the subject but I can't seem to get it to work. I uploaded my .fla in hope that some of you might be able to help me out and show me the right way to do this.
I am always open to learning anything so just tell me if it was something dumb that I overlooked. Thanks so much for the help guys.
[MX] Character Movement?
ok I have this character, that I want to go left, and I want it to change to another movie clip that appears to being going left. using this code I am able to go left but the removeMovieClip(); and attachMovie() doesn't work...please help
Code:
onClipEvent (enterFrame) {
if (Key.isDown(KEY.LEFT)) {
this._x -=10;
removeMovieClip(this);
attachMovie(charleft,charleft,_parent.getNextHighestDepth());
}
}
[F8] Character Movement
Hi, i created a flash game. I have my character moving and everything, but i want where i paint to be a boundary that rolls over and resets screen to frame 1. what is the code for this?
Character Movement
hello there, i just wanna ask if there someone who can help me in creating this kind of effect,
http://www.ff0000.com/
i like to know how to make those characters move, and i think there is also a physics there bec the character movement is slow decreasing when you stop clicking the arrow button
hope you guys to help me in here.
Help With Character Movement
I heave been working very hard to get a character to walk around and jump. I cannot get this to work for the life of me.
I got the solution from here: :http://www.rit.edu/~ndr0470/game_physics/
and I have this following code in my program but it will not work. My movie clips name is player and the bottom of my clip is 450 pixels, can anyone help me? I have been working on making a juimping guy for a day or two, this is starting to get sad. Thanks
//variables
var gravity = 3;
var moving = false;
var jumping = false;
function GameLoop() {
if(jumping == false && Key.isDown(Key.SPACE) == true ){
dy = 20;
jumping = true;
}
if (jumping == true){
if( player._y + dy > 450 ){
player._y = player._y + dy;
dy = dy - gravity;
}
else {
jumping = false;
}
}
if(moving == false && Key.isDown(Key.LEFT) == true){
moving = true;
dx = -10;
}
else if(moving == false && Key.isDown(Key.RIGHT) == true){
moving = true;
dx = 10;
}
else {
moving == false;
}
if (moving == true){
player._x = player._x + dx;
}
}
Character Movement.
I need a script within actionscript that will make an MC called CAR move with the key pads, does anyone have a script I could use.
Thanks sephers181
Code For Character Movement Please.
I have certain codes that I picked up and even tried my own, but how can i make the character move in the same direction as the arrow. You know like so when you press the left arrow it turns left instead of going backwards. Your replies will be very apreciated.
Thanks all who at least review this,
Character Animation And Movement Help
My charcter has 7 frames. The first one is the still one which I put stop() on. Then when it gets to frame 7, I have gotoAndPlay(2). For my movement code I used:
Code:
onClipEvent(enterFrame){
if (Key.isDown(Key.DOWN)) {
move(0, 4);
_parent.gotoAndPlay(4);
}
}
//
onClipEvent (keyUp) {
if (!Key.isDown(Key.DOWN)) {
_parent.gotoAndStop(1);
}
}
The problem is that it only plays the first frame of the animation.
Random Character Movement
I need to create something of a virtual town, it will be from the perspective of above looking down (GTA 1 style) in 2D. On one layer i have the buildings etc and on a layer beneath that i want some people to randomly be moving around.
I have some script in a controller mc that controls some random movement using three frames:
frame1:
code:
// set number of steps to reach target
loops = 0;
// create a random target
_root.target_x = Math.random()*550;
_root.target_y = Math.random()*400;
// find the difference and divide by 20 : will be distance of each step
_root.xdiv = (_root.target_x-_root.circle._x)/20;
_root.ydiv = (_root.target_y-_root.circle._y)/20;
frame2:
code:
// increment loop and step
loops++;
_root.circle._x += _root.xdiv;
_root.circle._y += _root.ydiv;
Frame3
code:
// increment loop and step again distance of single step
loops++;
_root.circle._x += _root.xdiv;
_root.circle._y += _root.ydiv;
// if 20 steps then we are at target so set a new one in Frame 1
// if not then go back to frame 2 and step again
if (loops<20) {
gotoAndPlay(2);
} else {
gotoAndPlay(1);
}
This works okay but for realism i need some changes, firstly as the mc will be a small human i need for them to be facing the direction they are travelling. I presume this will be worked out using trajectories or something but i'm useless with maths.
I also would like for them to have a set speed rather than using a set number of steps, they will move at this speed to the target until they reach it at which point a new target is set.
would really appreciate some help on this, thanks.
Character Movement + Actions
I am making a flash game based off of the playstation game castlevaniaL symphony of the night (view what i made so far at www.coreyisgod.com/sotn.html) but it has hence become really tedious and confusing with only the basic buggy movement i still have. here is the action controlling the movement
onClipEvent (load) {
move = 10;
}
onClipEvent (enterFrame) {
{
if ((Key.isDown(Key.RIGHT)) or (Key.isDown(Key.DOWN)) or (Key.isDown(Key.LEFT)) or (Key.isDown(Key.CONTROL))) {
{
if ((Key.isDown(Key.RIGHT))) {
this._xscale = 175;
gotoAndStop (1);
move = 10;
//cant move while ducking
if (Key.isDown(Key.DOWN)) {
move = 0;
}
this._x = this._x+move;
}
// code for left key press
if ((Key.isDown(Key.LEFT))) {
this._xscale = -175;
gotoAndStop (1);
move = 10;
//cant move while ducking
if (Key.isDown(Key.DOWN)) {
move = 0;
}
this._x = this._x-move;
}
// code for down key press
if ((Key.isDown(Key.DOWN))) {
gotoAndStop (2);
move = 0;
}
} else {
// display standing still
gotoAndStop (4);
}
}
the movie clip contains movie clips that activate when certain buttons are pressed... but this is getting monotonous
is there a better way to control characters for attacking, jumping, walking, ducking, etc, and play the animation of each? (flash 5 or mx)
Character Movement And Actions
I am making a flash game based off of the playstation game castlevaniaL symphony of the night (view what i made so far at www.coreyisgod.com/sotn.html) but it has hence become really tedious and confusing with only the basic buggy movement i still have. here is the action controlling the movement
onClipEvent (load) {
move = 10;
}
onClipEvent (enterFrame) {
{
if ((Key.isDown(Key.RIGHT)) or (Key.isDown(Key.DOWN)) or (Key.isDown(Key.LEFT)) or (Key.isDown(Key.CONTROL))) {
{
if ((Key.isDown(Key.RIGHT))) {
this._xscale = 175;
gotoAndStop (1);
move = 10;
//cant move while ducking
if (Key.isDown(Key.DOWN)) {
move = 0;
}
this._x = this._x+move;
}
// code for left key press
if ((Key.isDown(Key.LEFT))) {
this._xscale = -175;
gotoAndStop (1);
move = 10;
//cant move while ducking
if (Key.isDown(Key.DOWN)) {
move = 0;
}
this._x = this._x-move;
}
// code for down key press
if ((Key.isDown(Key.DOWN))) {
gotoAndStop (2);
move = 0;
}
} else {
// display standing still
gotoAndStop (4);
}
}
the movie clip contains movie clips that activate when certain buttons are pressed... but this is getting monotonous
is there a better way to control characters for attacking, jumping, walking, ducking, etc, and play the animation of each? (flash 5 or mx)
Character Movement With Mouse
Okay, i want to make a character and have him move to the spot where you clicked. so when you move your mouse in a direction he looks that way, and when u click somewhere like here -------------> he moves there!
If you can help please help!
Thank-u Codien Flame #1
[F8] Help With Character Movement In Game
I am trying to make a game in flash 8 but i got somewhat stuck now. The thing is the character is a movie clip with various animations inside of walking, atacking, jumping, etc...
So i am using the following code:
Code:
onClipEvent (load)
{
speed = 10;
}
onClipEvent (enterFrame)
{
if (Key.isDown(Key.SPACE))
{
this.gotoAndStop(2);
}
if (Key.isDown(39))
{
this.gotoAndStop(3);
_xscale = +100;
this._x = this._x + speed;
} // end if
if (Key.isDown(37))
{ _xscale = -100;
this.gotoAndStop(3);
this._x = this._x - speed;
} // end if
if (Key.isDown(Key.CONTROL))
{
this.gotoAndStop(4);
} // end if
if (Key.isDown(Key.SHIFT))
{
this.gotoAndStop(5);
} // end if
onClipEvent (enterFrame)
{
if (Key.isDown(Key.SPACE) && !jumping)
{
vel_y = 36;
jumping = true;
} // end if
if (jumping == true)
{
vel_y = vel_y - 2;
if (vel_y <= -15)
{
vel_y = -15;
} // end if
this._y = this._y - vel_y;
} // end if
if (_root.ground.hitTest(this._x, this._y + 35, true))
{
vel_y = 0;
jumping = false;
} // end if
}
onClipEvent (enterFrame)
{
this._y = this._y + 16;
if (_root.ground.hitTest(this._x, this._y + 1, true))
{
this._y = this._y - 16;
} // end if
}
onClipEvent(enterFrame) {
//change dimensions for document width
if(this._x >= 750) {
_root.ken._x = 750;
}
if(this._x <= 10) {
_root.ken._x = 15;
}
}
Ok everything works perfectly except when i jump diagonally cause as i do that i am pressing both walk and jump button and the animation gets stuck on the first frame of the walk animation. What i want to happen is that as soon as i press space (jump) the jump animation will play the hole way through untill it finishes, even if i press any other button.
Another minor problem that is not very important is the walk animation. I want the walk animation to imediatly stop as soon as i let go of the directional buttons.
i tried using:
onClipEvent(keyUp) {
_root.character.gotoAndStop(1);
walkSpeed = 10;
But that cut all my animations as soon as i released any button, when i just want it to happen when i released the left or right button.
Any help will be greatly apreciated.
[F5] Character Movement With Acceleration
onClipEvent (enterFrame) {
moveSpeed = 0;
_root.maincharacter._y += moveSpeed;
}
How would I alter this code so that when the 'maincharacter' falls, starting at moveSpeed = 0, it starts to gain more speed (as time or frames pass, whichever is easier). I would think it would be something like (_root.maincharacter._y += moveSpeed+acceleration*time), but I don't know exactly how to pull it off. Thanks!
Character Movement Problem
ok, so i'm working on making a game, and in this first part, i'm trying to play an animation and move the character when i press one button. Problem is, the character does not go through the entire, it goes through part of it once and just repeats, even if the key is off. I know the problem, but not how to fix it. I need to come up with an alternative to "onEnterFrame", because i think that makes it restart each time i go through the frame. here's my code:
this.onEnterFrame = function() {
if (Key.isDown(Key.UP)) {
this._y -= 5;
gotoAndPlay(2);
} else if (Key.isDown(Key.DOWN)) {
this._y += 5;
gotoAndPlay(7);
} else if (Key.isDown(Key.LEFT)) {
this._x -= 5;
gotoAndPlay(20);
} else if (Key.isDown(Key.RIGHT)) {
this._x += 5;
gotoAndPlay(14);
}
};
if anyone knows how to make it stop when i don't hit a key, and make it go through the entire animation, it would be great. thanks ^^
Random Character Movement
I need to create something of a virtual town, it will be from the perspective of above looking down (GTA 1 style) in 2D. On one layer i have the buildings etc and on a layer beneath that i want some people to randomly be moving around.
I have some script in a controller mc that controls some random movement using three frames:
frame1:
ActionScript Code:
// set number of steps to reach target
loops = 0;
// create a random target
_root.target_x = Math.random()*550;
_root.target_y = Math.random()*400;
// find the difference and divide by 20 : will be distance of each step
_root.xdiv = (_root.target_x-_root.circle._x)/20;
_root.ydiv = (_root.target_y-_root.circle._y)/20;
frame2:
ActionScript Code:
// increment loop and step
loops++;
_root.circle._x += _root.xdiv;
_root.circle._y += _root.ydiv;
Frame3
ActionScript Code:
// increment loop and step again distance of single step
loops++;
_root.circle._x += _root.xdiv;
_root.circle._y += _root.ydiv;
// if 20 steps then we are at target so set a new one in Frame 1
// if not then go back to frame 2 and step again
if (loops<20) {
gotoAndPlay(2);
} else {
gotoAndPlay(1);
}
This works okay but for realism i need some changes, firstly as the mc will be a small human i need for them to be facing the direction they are travelling. I presume this will be worked out using trajectories or something but i'm useless with maths.
I also would like for them to have a set speed rather than using a set number of steps, they will move at this speed to the target until they reach it at which point a new target is set.
would really appreciate some help on this, thanks.
Character Movement + Rotation
Hello,
I am currently working on a car racing game but I am new to designing the engine for my game such as the physics for my car. So, I took help from a tutorial but could'nt quite understand the trigonometry part, can you explain it.
The part I did not understand was,
x = Math.sin(_rotation*(Math.PI/180))*speed;
y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
if (!_root.hit.hitTest(_x+x, _y+y, true)) {
_x += x;
_y += y;
} else {
speed *= -.6;
}
}
Hope you can help me out,
Thanking You,
Chinmaya
P.S. I know how to convert degrees to radians and know a little about unit circles. The main part I dont understand is that why do we multiply the sin of angle(in radians) to the speed!
Attach Code
onClipEvent (load) {
speed = 0;
}
onClipEvent (enterFrame) {
// make the car go forward
speed += 0.1;
// tells the car to slow down after the speed of 20
if (Math.abs(speed)>20) {
speed *= .7;
}
// you can change the rotation of the car to your desire
if (Key.isDown(Key.LEFT)) {
_rotation -= 15;
}
if (Key.isDown(Key.RIGHT)) {
_rotation += 15;
}
// here is where the hittest is for the boundary
speed *= .98;
x = Math.sin(_rotation*(Math.PI/180))*speed;
y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
if (!_root.hit.hitTest(_x+x, _y+y, true)) {
_x += x;
_y += y;
} else {
speed *= -.6;
}
}
Character Movement Flash Mx
i am new to flash and am making a game and i am having problems with the actionscript
i have made the movie clips for my character walking in 4 different directions but i have no idea how to make it so when the up arrow key is pressed, for instance, the movie clip of my character walking up is played.
if anyone has any ideas... plz reply
Flash 8 - Character Movement
Well, hello to you all and happy new year!
I'm creating a little game for a learning center. And the game consist of a character walking to other characters to learn more about them. Its a little village and everybody is there to learn. Ok, enough of that...
EDIT: THE GAME IS NOT TILE BASED, ITS VECTOR BASED, SO I HAVE BIG AND SMALL SPRITES ON SCREEN. WHAT MAKES THE COLLISION IS A BOX INSIDE THE SPRITES, BOX NAMED COLISION FOR ALL THE SPRITES ON STAGE.
ALSO, THE SPRITES ON STAGE ARE NAMED "Sprite1, Sprite2, Sprite3, etc" EXEPT FOR THE "player".
So far, I made the character move and go everywhere... by using this code.
I have a controller that calls a function()
Code:
onClipEvent (enterFrame) {
_root.detectKeys();
}
Now, after that happens, my detectkeys(); is as follow
Code:
function detectKeys() {
//---------------------------- Colision start
for (var i in _root.MainScrollerMC) {
if (typeof (_root.MainScrollerMC[i]) == "movieclip") {
if(i == "player"){
//trace("Do Nothing its the player! - " + i);
}else{
if(_root.MainScrollerMC.player.colision.hitTest(_root.MainScrollerMC[i].colision)){
//trace("colision with: " + i);
PlayerColision = 1;
break;
}else{
//trace("Not Colided you can move");
PlayerColision = 0;
break;
}
}
}
}
//------------------------------ Colision ends
// Send the parameters to move the character
var ob = _root.MainScrollerMC.player;
var keyPressed = false;
if (Key.isDown(Key.RIGHT)) {
keyPressed = _root.moveChar(ob, 1, 0);
} else if (Key.isDown(Key.LEFT)) {
keyPressed = _root.moveChar(ob, -1, 0);
} else if (Key.isDown(Key.UP)) {
keyPressed = _root.moveChar(ob, 0, -1);
} else if (Key.isDown(Key.DOWN)) {
keyPressed = _root.moveChar(ob, 0, 1);
}
// walk animation
if (!keyPressed) {
ob.clip.char.gotoAndStop(1);
} else {
ob.clip.char.play();
}
}
Ok, so far everything is working! So the characters is asking to the function named moveChar(characterMC, dirX, dirY) if it can move it. and the function is as follow:
Code:
function moveChar(ob, dirx, diry) {
// Variables used in this function
var MainScroller = _root.MainScrollerMC;
var CharPlayer = _root.MainScrollerMC.player;
var Speed = _root.Speed;
// going up
if (diry == -1) {
// Player Face Direction
CharPlayer.gotoAndStop("back");
// no wall in the way, move on
CharPlayer._y = CharPlayer._y-Speed;
// scroll the map
MainScroller._y = MainScroller._y+Speed;
}
// if going down
if (diry == 1) {
// Player Face Direction
CharPlayer.gotoAndStop("front");
// no wall in the way, move on
CharPlayer._y = CharPlayer._y+Speed;
// scroll the map
MainScroller._y = MainScroller._y-Speed;
}
// if going left
if (dirx == -1) {
// Player Face Direction
CharPlayer.gotoAndStop("left");
// no wall in the way, move on
CharPlayer._x = CharPlayer._x-Speed;
// scroll the map
MainScroller._x = MainScroller._x+Speed;
}
// if going right
if (dirx == 1) {
// Player Face Direction
CharPlayer.gotoAndStop("right");
// no wall in the way, move on
CharPlayer._x = CharPlayer._x+Speed;
// scroll the map
MainScroller._x = MainScroller._x-Speed;
}
// Refresh the screen
_root.UpdateScreen();
// End Function
return (true);
}
Ok, at this point the character moved and everything is working. My problem is that I don't know how to make him stop, when the colision boxes inside each spriteoverlap each other.
I have managed to crash the computer several times and I have also stopped permanently the character. I mean, after it touches a colision box... it will stick to it for good. Is like because it is touching, doesn't le go.
A little help here.. Thanks!
- Alex
Advanced Character Movement Using Keypad.
Hello,
Im creating a fantasy game and i want to be able to make a walking system. This will include perspectives and shadows. For the sake of arguement lets say the character walks up a path, as he walks up, his body becomes smaller, he becomes slightly dark tinted and he moves up the screen, as he walks down the path he then gets bigger and becomes light and of course further down the screen. Same with moving left / right and so on. If something is in the way, how would i then stop the character from being able to walk over the top if it? When i want the character to perform an action at a certain place of the screen how would i go about doing that?
How would i go about learning how to do this, or gaining knowledge of how you would go out programming something like this. If you know any links / source code / tutorials or you can help that would be extremely useful, thanks for your time
James
Game Character Movement Code
I am trying to make an action style game. I have the main character set up as an MC with other MCs inside it on the different frames. These are the graphics for crouching, walking right, etc. So frame 5 of the main MC is the graphic for walking right.
I have coded it so when right is pressed then the MC jumps to frame 5, but when i add in the code for walking left, nothing happens.
The current set up is 4 dynamic text boxes that display 0 or 1 depending on whether UP, DOWN, LEFT or RIGHT are pressed. The main MC then looks at these and then plays the appropriate frame. I don't know why I didn't just use straight forward
if (Key.isDown(Key.RIGHT)) {
this.gotoAndStop(5);
}
I have the FLA file ready to send via email cos its too big to fit on the forum. Please say so here or email me if you would like it. The fla has little explanations all over it to make it clearer.
I'm in flash 5 so if you do anything in MX please convert it to flash 5 format.
============
TiMo
Wall Code Without Character Movement
basically is there any way to make a code to make a movie clip a solid object that any other movie clips cannot go through, but without that code containing anything for the movement of the character.
So the code just makes the movie clip a solid object and nothing else?
Character Walking Movement With Mouse?
Hey guys-
Anyone ever try to have a mc animation move up, down, left, right and of course idle(stop) using the mouse (eg in place of the cursor) I'm sure it can be done but haven't had a chance to experiment. Thanks in advance for any feedback.
Best!
Character Movement Making Him Jump
Hiya again,
you may have seen my previous post about arrays, well i'm still learning and have set myself another project which i've got stuck on. I have a character that, walks left and right (on respective key presses) and stops facing the way he is going. My problem i have now is i want him to jump on the up key press. How do i do this ?
Heres my FLA file... perhaps someone can advise me on what to do.
Character movement thingy
Character Movement Using Mouse Clicks
Could someone help me figure out how to move a game character using mouse clicks versus the arrow keys, I would like to create a game were you click were you wanna go????
Any suggestions???
Thanks...
[CS3] Simple Character Movement Actionscript
I was trying to follow a tutorial on making a character move with the arrow keys. The only problem I have is when I add my character movie clip to the main timeline and try to select it to add the actionscript to it it says "Current selection cannot have actions applied to it" in the actions panel and so I can't up the script in there. Does anyone have any idea why its saying this?
Honestly, I have the stupidest problems with Flash sometimes. Someday I'll be good at it...someday...
Here's the tutorial if it helps: http://www.flashperfection.com/tutor...eys-73583.html
Game Character Movement Question.
I'm making a game with a top down view like in The Legend of Zelda for SNES (not directly top down but at an angle). I want my character 'hero' to go to the walk cycle for the appropriate direction nested in the hero timeline when the arrow keys are pressed. Then, when that key is released I want him to stay facing that direction but go to the frame of him standing still. I can successfully do this with the "right" arrow key and but will play the first frame of the correct walk cycle when the other keys are pressed but when the keys are released it jump to the facing right standing still frame. The right key's code comes first so I think it's a compatibility issue with the other keys. Here is my code for the right key and it's the same for the other keys.
onClipEvent (load) {
speed = 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x = this._x+speed;
gotoAndPlay("WalkRight");
}
if (!Key.isDown(Key.RIGHT)) {
gotoAndStop("StandRight");
}
It makes sense that adding a variable "heroPosition" would work if when the key's are pressed have the variable be that key (ex. if right key is pressed heroPosition = "Right") and then make the second if statement for the key if (heroPosition = "Right" && !Key.isDown... etc. This doesn't work. P.S. First time poster.
Game Actionscript - Character Movement
hi guys i have this AS code and am no sure what i would need to add/change to allow the character to fall from a platform if they're no longer on it... currently the character stays at the same _y position even when its no longer on thew platform
can any1 help me out with the changes i need
heres the code i currently have
Code:
onClipEvent (load) {
y_start = _y;
jumping = false;
jumpspeed = 0;
speed = 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
this.gotoAndStop("Walking Left");
this._x -= speed;
}
if (Key.isDown(Key.RIGHT)) {
this.gotoAndStop("Walking Right");
this._x += speed;
}
if (jumping) {
this.gotoAndStop("Jumping");
_y += jumpspeed;
jumpspeed += 1;
if (_y>=y_start) {
_y = y_start;
jumping = false;
}
} else {
if (Key.isDown(Key.SPACE)) {
jumping = true;
jumpspeed = -10;
}
}
if (_root.Platform.hitTest(this._x, this._y, true)) {
jumping = false;
}
}
Character Movement With Mouse Click?
So, I know how to do it with AS2. I make a movie clip and assign the code below to it, and when I press Ctrl+ Enter to preview it, I can click anywhere in my stage and the circle (movie clip) will move to it. Any direction.
Now, I know nothing about (AS2 or) AS3. I've only done like....3 tutorials. I would love some help. I would greatly appreaciate it. be very clear if you can, I know NOTHING.
So; overall; how to I make an object move with mouse clicks using AS3?
I don't even know how to use the instance to make the object move. Please help!
Attach Code
onClipEvent (load) {
rad = 0.0174532925199433;
speed = 5;
moving = false;
}
onClipEvent (mouseDown) {
moving = true;
m = {x:_parent._xmouse, y:_parent._ymouse};
}
onClipEvent (enterFrame) {
if (moving) {
mcx = _x-m.x;
mcy = _y-m.y;
_rotation = -Math.atan2(mcx, mcy)/rad;
mr = _rotation*rad;
if (Math.sqrt((mcx*mcx)+((mcy)*(mcy)))>speed) {
_y -= speed*Math.cos(mr);
_x -= -(speed*Math.sin(mr));
} else {
_x = m.x;
_y = m.y;
moving = false;
}
}
}
Play To And Stop (character Movement MC)
Hello helpful flash friends. I need some help or a glass of water thrown in my face.
I have a MC which is a lady that raises her arms up and down. From the main timeline i want to tell that "ladyMC" (also sitting on the main timeline) to play to and stop on specific frames. I have tried it two different ways but am obviously missing something.
The first way i tried just using an if/else and getting the current frame #.
Code:
if(lady._currentframe < 22){
lady.play();
}else if(lady._currentframe >= 22){
lady.stop();
}
The second way i tried setting a variable (which is being passed successfully) so that when the ladyMC hits the frame i want it to stop on, it changes the variable.
Code:
lady.play();
if(ladyvar==2){
lady.stop();
}
In both examples, the ladyMC plays through and never stops. Your help is appreciated. This seems so simple but is driving me crazy.
Play To And Stop (character Movement MC)
Hello helpful flash friends. I need some help or a glass of water thrown in my face.
I have a MC which is a lady that raises her arms up and down. From the main timeline i want to tell that "ladyMC" (also sitting on the main timeline) to play to and stop on specific frames. I have tried it two different ways but am obviously missing something.
The first way i tried just using an if/else and getting the current frame #.
Code:
if(lady._currentframe < 22){
lady.play();
}else if(lady._currentframe >= 22){
lady.stop();
}
The second way i tried setting a variable (which is being passed successfully) so that when the ladyMC hits the frame i want it to stop on, it changes the variable.
Code:
lady.play();
if(ladyvar==2){
lady.stop();
}
In both examples, the ladyMC plays through and never stops. Your help is appreciated. This seems so simple but is driving me crazy.
Character Movement Animations Wont Work
here's my problem - I've created a stick character that'd i'd like the user to move to try to get a handle on interactivity. I've created a buncha movie clips within movie clips - pretty sure this is how you do it, - but when I export it as a movie only one of my animations works when you press a key. The spacebar jump won't work... the left walk won't work... but the right walk does, as well as the idle animation.
when i remove the 'else' statement that holds the key to the idle character animation all my animations work... but then the character never goes idle, and the other animations loop.
if anyone could please help it'd be greatly appreciated
thanks in advance
(flash mx)
Trigonometry Mouse Rotation And Movement Of A Character
Hi Everyone,
I was wondering if anyone knew a script for making a MC rotate by moving the mouse, and then making him move what ever way he is facing by pressing the "up" arrow.
Any answers would be appreciated
Thanks,
Mr_Welfare
_______________________
Flash MX 2004 Professional
[MX04] Background, Foreground, And Character Movement.
Okay so I need help with my character. I followed this tutorial: http://www.awestyproductions.com/tut...ng-background/
And I have my character and background working but I'd like to add the foreground - since I've been using Actionscript for like a day now I have no idea how to alter the code. It's probably a simple case of duplicating it but I'm not sure how.
Can anyone shed some light?
[F8] Character Movement Though Rotating Round Surface
Hi im a flash action script noob and i need some help with my project.
i want a character to move on a globe. the movement of the character is shown though not by shifting the positions of the caharcter but by the rotation of the surface of the globe. buttons are used to move leftward and rightward.
Also, there are three layers of the globe to show depth. how would i script it so that the layers of the globe rotate at different speed?
i've uploaded a zipped of a swf file.
appreciate ur help
Game Character Movement Action Script
I have a character in a movieclip with contains movieclips on the timeline which I've applied behavior to but I have problems when I try to use any of the letter characters to apply a key press comand. Could some one please check out the attached file and see if they can offer a solution. Also can someone please provide an answer to the problem of a character returning to it's orginal position. rather than staying in the last position used.
The file can be found here -
Problem File
Game - Character Movement Problems [renamed]
Hello.
I thought i would have a go at making a platform game in Flash MX 2004.
However i can't get my charecter move
I have tried so much, however, i'm just stupid!
I am trying to script my movie clip so that:
When the key 'E' is pressed the charecter moves right.
When the key 'Q' is pressed the charecter moves left.
When the key 'W' is pressed the charecter jumps.
When the key 'S' is pressed the charecter crouches (either changses to crouching movie clip or squashes current movie script if this is possible.).
When the key 'D' is pressed the charecter moves right while crouched.
When the key 'A' is pressed the charecter moves left while crouched.
I have a charecter that is a movie clip. This is what i want to move.
When the charecter jumps or is in the air i want my charecter to fall down until it reaches a movie clip with the instance name of 'platform'
When the charecter crouches i either want it to change movieclip or sqaush the current movie clip.
The charecter must alwaysbe touching a platform unless if it is jumping
Please can someone help me?
My File
This is what i have. I have removed the actionscript that i had because it didn't work Please can someone tell me what i should put, or even better alter the file for me
Thank You
|