how can I change an object's centre

Started by fitbo, Fri 17/03/2006 16:20:57

Previous topic - Next topic

fitbo

Hey, I looked everywhere but I can't find a solution to my problem.
Here it is: when the player walks in front of a car who is passing by he is instantly killed, but the animation comes too late. The car is an object and I used the following code in the global script:

if (character[ARTHUR].IsCollidingWithObject(object[12])==1)
player.LockView(15)&&
player.Animate(0, 5, eOnce, eNoBlock, eForwards)&&
Wait(120)&&
QuitGame(0);

The animation only starts when the car is already one third passed the player, but I want that the animation starts the moment the player is hit by the car and not later. I tried using a different object (a bumper)
and placed it on the car. However that doesn't did any good, because the animation only starts when the player is at same y axis than the car. So when the players feet are at same position as the car's wheel (and not the bumper) the animation doesn't start. So I replaced the bumper by an black 25*10 image (it is exactly as high than the street) that I placed before the car (the image is invisible in the game), so that the player would be killed at the correct moment, but the animation didn't start at all.
I thought of making the street an region and write a script when the player stands on it, but I encountered another problem (the subject of the topic):
the center of the car is at the very end, on the bumper, and I wonder how the center can be changed to the front of the car, there where the player should collide with it and then be killed.

Some help would be great




Ashen

I'm not sure whether that code would work anyway - you can't join commands with the && operator. It should be:
Code: ags

if (character[ARTHUR].IsCollidingWithObject(object[12])==1) {
  player.LockView(15);
  player.Animate(0, 5, eOnce, eNoBlock, eForwards);
  Wait(120);
  QuitGame(0);
}


What if you use the AreThingsOverlapping(..) command instead? Since it checks the whole of the object/character (as opposed to IsCollidingWithObject() which only checks against the lower third of the character) it should return the collision sooner. You might need to play around with the value a bit, as it counts transparent areas in the overlap. (I.e. overlap == 1 would probably be a few pixels away from the bumper seeming to hit the character, but overlap == 8 would look right.)

Alternatively, could you just directly compare the X coords of the character and object, e.g.:
Code: ags

if (obejct[12].X >= cArthur.x - GetGameParameter (GP_SPRITEWIDTH, object[12].Graphic, 0, 0) {
  //If the object is closer than it's own width to ARTHUR
  player.LockView(15);
  player.Animate(0, 5, eOnce, eNoBlock, eForwards);
  Wait(120);
  QuitGame(0);
}
I know what you're thinking ... Don't think that.

fitbo

I used:

if (AreThingsOverlapping(1012, ARTHUR)) {
  player.LockView(15);
  player.Animate(0, 3, eOnce, eNoBlock, eForwards);
  Wait(120);
  QuitGame(0);
}

but I got the following error message:
Error: AreThingsOverlapping: invalid parameter

I also tried

if (obejct[12].X >= cArthur.x - GetGameParameter (GP_SPRITEWIDTH, object[12].Graphic, 0, 0)) {
  //If the object is closer than it's own width to ARTHUR
  player.LockView(15);
  player.Animate(0, 5, eOnce, eNoBlock, eForwards);
  Wait(120);
  QuitGame(0);
}

but there again I got an error message:

Error(line44): undefined symbol 'object'



Ashen

I'm not sure why the first one gives that error - as far as I can see it's copied directly from the manual example, and should work fine. What if you try the parameters teh other way around ((ARTHUR, 1012)), or use player.ID in place of ARTHUR?

The second one is probably because I mis-spelt 'object' in the condition (it actually says if(obejct[12].X == ...), and you didn't notice when you copied the code over.

Something else I just noticed (although it's not related to the problem): Why are you using a non-blocking animation, followed by a Wait(..) command? Why not just use a blocking animation?
I know what you're thinking ... Don't think that.

fitbo

I tried what you said, but I still get the two same error messages for the two commands

Ashen

What if you give the object a script name, and use that in place of object[12]? (E.g. call it 'CAR' and use oCar.X, oCar.Graphic.)

As an almost-last-resort - what if you make the car a Character, rather than an Object. That way you can use Character.LockViewOffset to change the cars 'centre', as you originally asked.
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk