Click, walk to mousex/y

Hi, im currently making a game with basicly looks like a char in de middle of the screen and an landscape around it.
Now i want the player to click on anywhere on the background, and the char to walk towards that point.
It’s easy to make the char mc jump right to that point, but i want it to walk (play a walking mc) and move there in a certain speed. So it looks like the char is smoothly walking to that location.

I know about _xmouse/_ymouse etc. and about the walking movement and direction/sideview of the char that has to be shown for where it walks (click lower than current location will show the front of the char, left will show left side etc.). But can’t figure out how to move the char in certain speed between the current point and the new location.

This tutorial shows you how to make mouse buttons:
http://www.actionscripts.org/tutorials/beginner/games_in_flash/index.shtml

This archive post shows you how to make an object go where the mouse is located:
http://www.kirupaforum.com/forums/archive/index.php/t-44757.html[url=“http://www.kirupaforum.com/forums/archive/index.php/t-46786.html”]

To get what you want, instead of running the paddle movement “OnClip Entry”, run the movement when you click the mouse button.

Thats not exactly what i meant… or i couldnt find what you were refering to.
Anyway… i’ve been testing a bit, and here’s what i came up with: (attachment)

As you can see it follows the mouse in the right direction in de first file.
In the second file it keeps moving towards the mouse, it just doesnt go directly towards the clicked spot because of the xspeed = 10 stuff, and it doesnt knw when to stop because it doesnt keep checking wether it passed the clicked spot or not.

Hope you, or anyone, can see how to improve it

Here’s a couple hints:

  1. If you keep clicking and clicking and clicking on your animation, it will say something like:
    x: 10, y: 10, xvar: 10, yvar: 10, xmc 133.15, ymc 216.45

The numbers don’t change, but the ball randomly flies off in different directions. That’s a good clue. Figure out why it’s doing that with your current code.

  1. Also, if you click it and let it go for 2 minutes, then click it again 2 minutes later, it will arrive back on-screen 2 minutes from now.

Check if CurrentX and CurrentY values for your MC Ball Movie Object are > or < the window size, and if it is, you can flip positive to negative. Then if the MC ball goes off screen it will reverse course. (Or start subtracting xvar if you were adding xvar.)

To keep track of this in ActionScript, read step 3.

  1. CurrentX and CurrentY, I think that’s your x and y values in your sample FLA attached. If CurrentX > StageHeight then Make “InView” Variable True. If it’s FALSE then the show can’t go on because InView has to be true.

Change your code a bit:

if (_root.down == “yes” && InView == “yes”){
_root.mc._y = _root.mc._y + _root.yspeed;
}
if (_root.down == “yes” && InView != “yes”){
_root.mc._y = _root.mc._y - _root.yspeed;
}

I am making an RPG at the moment, and I have the character actually move towards the location of the mouse click, as well as rotate properly. If you would like, I could send you the files to look at it.

[color=blue]bhjodokast:[/color]
I know what you mean, and that would definately apply if i wanted to make a breakout game, or any other game with a ball that bounces inside the stage.
But the ball in my example is just a test object. This will later be a character that walks towards the mouse click.

So what i want to happen is that the ‘ball’ moves to where you clicked on the stage, and then stop there.
So quite like the one in the first example (loc_move.swf) but with clicking only once.

[color=blue]Behemoth-Dan:[/color]
[color=black]Yeah sure, that sounds like what i’m trying to do.[/color]

anyway… here’s my latest (working) version of what i meant.

Would this, by any chance, be of help?

its pretty cool!

but the point was to make it move at a standard speed. Your example takes 0,5 sec wherever you click. For a walking character, this would be irrealistic.

Ok