direction check?

Started by Shade, Sat 20/08/2005 10:36:05

Previous topic - Next topic

Shade

how can in check from which direction the character.Ego collides with another character or object? i need this because i wanted to make something like: here is the crate put it on the button right here. so the character has to push it to the right position. but how can i check from which direction he pushes?

Colxfile

You could use the character.LOOP property. This returns the current loop of the character's animation, so if the player is facing left, you could deduce that is has approached the box from the right. But since it doesn't follow that the player's loop determines where he is relative to the box, you can test the difference between the box's x coordinate and the character's x coordinate. For example:
Code: ags

if (object[1].x > cEgo.x) {
 //What happens if Ego is to the left of the box
}
else if (object[1].x < cEgo.x) {
 // What happens if Ego is to the right of the box
}

(Replace 'object[1]' with whatever represents the box in your script.)
Always carry a UV marker pen with you. When you go to a shop or a friend's house, if you see something you like, put your name and postcode on it. If it gets stolen and subsequently recovered, the police will get in touch with you so that they can 'return' it.

Shade

but if i would do it like in your code the the box could stand on the right edge and the character on the left and it would happen something. and if i would test the difference between the box's x coordinate and the character's x coordinate it would not really work i think. e.g. i am checking wether the character is 1-5 x coordinates left from the box. if this is true something is going to happen. but the character could face up in this area and the box moves right. probably i don't really get what you mean. if it's so i am sorry. so could you please eyplain it in more detail to me? thx

Colxfile

#3
Sorry, I misread the situation. Looks like you may also need to use additional commands, including the 'IsCollidingWithObject'.

Here's a plan, with illustrative download. (<700KB)
You will need AGS 2.7 for it to work. Have a play with it

To do this in your game, you will need to:
1: Place a region near the box (Say... to the right of it). Suppose it's region 1, and it's adjacent to object 0. The region will need to overlap the area where the box is placed.
2: In the interaction editor for that region, add a new 'run script' command under 'While standing on the region'. In the script, place following command:
Code: ags

if (cEgo.IsCollidingWithObject(object[0]) && (cEgo.Loop==1)) {
	object[0].Move(object[0].X-40, object[0].Y, 5, eBlock, eWalkableAreas);
	}

So... while standing on the region, if cEgo collides with the object AND he is facing Left (Loop is 1) the box moves.
I only threw the example together in a short time, thus it is undocumented and uncommented. If you have any questions, just ask :)
Always carry a UV marker pen with you. When you go to a shop or a friend's house, if you see something you like, put your name and postcode on it. If it gets stolen and subsequently recovered, the police will get in touch with you so that they can 'return' it.

Shade

thx  :D
i think i can work with that.  :D

Colxfile

Just to warn you, I recently re-uploaded that file with newer code. Before, it was one huge if command in the 'repeatedly execute' block of the room script. If that's what you see, then it WILL work, but the newer version has it in the 'While standing on region' part, so it is not as scary :)
Always carry a UV marker pen with you. When you go to a shop or a friend's house, if you see something you like, put your name and postcode on it. If it gets stolen and subsequently recovered, the police will get in touch with you so that they can 'return' it.

SMF spam blocked by CleanTalk