How to move straight from the direction the character is facing

Started by joelphilippage, Sat 20/01/2007 01:19:11

Previous topic - Next topic

joelphilippage

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.



Rui 'Trovatore' Pires

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.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

joelphilippage

Thanks for the help. ill try this out.

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

the character still dosin't move.



Rui 'Trovatore' Pires

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
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

joelphilippage

okay ive got another problem, it is moving the mouse and not the character



Ashen

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?
I know what you're thinking ... Don't think that.

Rui 'Trovatore' Pires

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.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

joelphilippage

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.



Ashen

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? At the least, you could see how it's coding works.
I know what you're thinking ... Don't think that.

joelphilippage

this is the code im using now for pressing up.
Code: ags
if (keycode ==372) {
		if (cCar.Loop == 4) {
		  character[CAR].WalkStraight(player.x, player.y-500);
		}
		}



Rui 'Trovatore' Pires

#10
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*
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Ashen

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.
I know what you're thinking ... Don't think that.

joelphilippage

Yes that works. but the mouse moving is still there.



Ashen

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.)
I know what you're thinking ... Don't think that.

Rui 'Trovatore' Pires

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!
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

joelphilippage

ok I found it in the Enhanced Verb Coin module script

EDIT: Now its working perfectly



Ashen

I know what you're thinking ... Don't think that.

joelphilippage

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.



Ashen

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. (Might need a little tinkering, but IIRC it does work.)
I know what you're thinking ... Don't think that.

Rui 'Trovatore' Pires

Or, with Anti-glide on, change the animation speed. Might work.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

SMF spam blocked by CleanTalk