Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: joelphilippage on Sat 20/01/2007 01:19:11

Title: How to move straight from the direction the character is facing
Post by: joelphilippage on Sat 20/01/2007 01:19:11
I have looked through the character commands and cain't find a command for moving the character staight twoard the direction the character is facing. Sort of like in a 3d game like monkey island 4 where if you push the up arrow the character will move foward from that direction. Is there a way to do this in ags? It would also be helpfull to have a back key to move them back.
Title: Re: How to move straight from the direction the character is facing
Post by: Rui 'Trovatore' Pires on Sat 20/01/2007 10:15:17
get the characters' LOOP to get the direction
if (the loop # means he's facing right) WALKSTRAIGHT(player.x+500, player.y, nonblocking)

Stuff like this. Hope it helps. :) To move them back... not sure what you mean by that, but reverse the code and maybe you have it.
Title: Re: How to move straight from the direction the character is facing
Post by: joelphilippage on Sat 20/01/2007 14:20:31
Thanks for the help. ill try this out.

EDIT:
Ok ive tried this out with this code:
if (keycode ==372) {
if (cCar.Loop == 4) {
  character[CAR].WalkStraight(player.x, player.y);
}
}

the character still dosin't move.
Title: Re: How to move straight from the direction the character is facing
Post by: Rui 'Trovatore' Pires on Sat 20/01/2007 15:05:06
Move to player.x player.y? You're telling the character to move to the X and Y coordinates it already is at.

RIGHT: player.x+500 (or some big number like that), player.y
LEFT: player.x-500, player.y
UP: player.x, player.y-500
DOWN: player.x, player.y+500
Title: Re: How to move straight from the direction the character is facing
Post by: joelphilippage on Sat 20/01/2007 15:08:06
okay ive got another problem, it is moving the mouse and not the character
Title: Re: How to move straight from the direction the character is facing
Post by: Ashen on Sat 20/01/2007 15:10:25
Also (or if cCar isn't the player character), it may be that the code is being called as long as the key is held down - meaning cCar is never given the chance to move - so you might need to do an IsKeyPressed (or similar) check. And, of course, check that there's definitely a Walkable Area for cCar to use.

EDIT:
I don't know if it's possible to move the mouse with that code, only by using Mouse.SetPosition. What exactly is happening?
Title: Re: How to move straight from the direction the character is facing
Post by: Rui 'Trovatore' Pires on Sat 20/01/2007 15:11:38
Ayuh, what Ashen said - I kinda assumed those were self-evident bits, when you first posted this in the Techie board. :)

Re moving the mouse... huh? That code shouldn't do that. There must be something else causing that behaviour.
Title: Re: How to move straight from the direction the character is facing
Post by: joelphilippage on Sat 20/01/2007 15:14:15
Well i know the car is the player character and that there is a walkable area in the room because i can use the mouse to move the car.
Title: Re: How to move straight from the direction the character is facing
Post by: Ashen on Sat 20/01/2007 15:32:09
WalkStraight will move the character as far as it can towards the location in a straight line until it hits a void in the Walkable Area, while using the mouse will work out a path to get where you clicked. So, it's possible you've got a walkable area but, if there's holes in it, the Character might just be poorly placed and not able to WalkStraight in the direction you want.

Have you tried the IsKeyPressed check, and changed the WalkStraight coords as Rui suggested? What's the complete code you're using now?

EDIT:
If all else fails, why not try the KeyboardMovement module (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=22724.0)? At the least, you could see how it's coding works.
Title: Re: How to move straight from the direction the character is facing
Post by: joelphilippage on Sat 20/01/2007 15:37:59
this is the code im using now for pressing up.
if (keycode ==372) {
if (cCar.Loop == 4) {
  character[CAR].WalkStraight(player.x, player.y-500);
}
}
Title: Re: How to move straight from the direction the character is facing
Post by: Rui 'Trovatore' Pires on Sat 20/01/2007 15:39:58
Do a search in your script for:

Mouse.SetPosition
mouse.x=
mouse.y=

Show us what you come up with. Theoretically, only these commands should change the mouse's position.

EDIT - *looks down at Ashen's post. Looks up at the code. Looks stupid, smacks his head and goes sulk in a corner for not spotting it*
Title: Re: How to move straight from the direction the character is facing
Post by: Ashen on Sat 20/01/2007 15:42:55
Wait a minute ... loop 4 is 'Down Right'. What about using if (cCar.Loop == 3) {, since that's the 'Up' loop. (Always the obvious stuff you miss...)
EDIT: In fact, try if (cCar.Loop == 3 && cCar.Moving == false) { or it might freeze up a bit due to repeated calls.

Still don't see why it'd be moving the mouse, though.
Title: Re: How to move straight from the direction the character is facing
Post by: joelphilippage on Sat 20/01/2007 15:47:39
Yes that works. but the mouse moving is still there.
Title: Re: How to move straight from the direction the character is facing
Post by: Ashen on Sat 20/01/2007 15:51:00
Have you searched for those terms Rui mentioned? I'm not even sure you can directly modify the mouse position (e.g. mouse.x = 50;) so it could just be Mouse.SetPostion you're after.
Unless it's that the room is scrolling with the Character, so what's UNDER the mouse changes but the mouse doesn't actually move? (Or you mean the Character can be moved with the mouse, and you don't want them to be.)
Title: Re: How to move straight from the direction the character is facing
Post by: Rui 'Trovatore' Pires on Sat 20/01/2007 15:52:02
Ashen, we keep posting the same things at the same! :D

Except you sound cleverer and expand on the things I say. Good on ye!
Title: Re: How to move straight from the direction the character is facing
Post by: joelphilippage on Sat 20/01/2007 15:56:10
ok I found it in the Enhanced Verb Coin module script

EDIT: Now its working perfectly
Title: Re: How to move straight from the direction the character is facing
Post by: Ashen on Sat 20/01/2007 16:04:13
Glad to hear it!

And, please don't double post.
Title: Re: How to move straight from the direction the character is facing
Post by: joelphilippage on Sat 20/01/2007 16:43:53
also, how could I get the car to increase its speed the longer you hold the up button down to a certian point. its not possible to set the walk speed while walking. This would make it move sort of like a car.
Title: Re: How to move straight from the direction the character is facing
Post by: Ashen on Sat 20/01/2007 16:53:34
I don't think that's possible. As you say, you can't increase the walking speed while the Character is moving, and stoping them, even for a single gameloop, to up the speed just looks wrong.

To do it, I guess you'll need to manually alter the Character's position based on the direction they're facing, and increase the amount to change it by based on their speed. A little complicated, but I think someone's already done the bulk of the work for you HERE (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=21384.0). (Might need a little tinkering, but IIRC it does work.)
Title: Re: How to move straight from the direction the character is facing
Post by: Rui 'Trovatore' Pires on Sat 20/01/2007 20:27:11
Or, with Anti-glide on, change the animation speed. Might work.