object animating and moving

Started by vpresrufus, Sun 03/04/2005 21:30:48

Previous topic - Next topic

vpresrufus

basically im having trouble making an object animate and move. for example, i want it to appear like the item is being thrown. so i want an object to appear infront of the player, go to the destination in the throwing animation, then disappear. anyone know how i can accomplish this?
thanks in advance

DoorKnobHandle

If you want your object to - let's say - spin and be thrown at the same time, you don't draw it animated (spinning) and then let it move via scripting. Instead you draw both animations in one animation.
That way you can even let objects be thrown in realistic curves and not only in straight "walk to" movements...

Got me?

vpresrufus

i see. but im still unsure how to do this:S keep in mind im a newbie:P sorry to be a pain

Candle

Code: ags
MoveObject
MoveObject (int object, int x, int y, int speed)

Starts the object OBJECT moving from its current location to (X,Y). It will move at speed SPEED, which uses the same scale as the character Walk Speed values in the Room Editor.
Example: 

MoveObject(2,125,40,4);
while (IsObjectMoving(2)==1) Wait(1);

will move object 2 to 125,40 and return control to the player when the object gets there.
See Also: IsObjectMoving, MoveCharacter, MoveObjectDirect, StopObjectMoving



vpresrufus

woop thanks alot ppl:)
much appreciated!

physics

remember that the only force affecting a thrown object is gravity (G=mg). After the movement starts the x speed is the same all the way (acceleration=0). The y-speed is affected by gravity acceleration g (=9.8 m/s^2). At the beginning the thrown object is  slowing down at 9.8 m/s until it reaches the highest point; after that is falling, accelerating at 9.8 m/s until it hits ground or something. This applies ofcourse only if throwing speed is below 10% of light speed ;)

TerranRich

Um...you don't really need all that physics jargon. Just make the entire path of the object one single animation.
Status: Trying to come up with some ideas...

RestoreGame

Hello!
I have tried googling and checking the forum for an answer (but the search function is out of order now) and I finally found this thread.
I kind of have the same problem as the guy who started this thread, but I didn't exactly get an answer to the question.
I want a shuttle to move from the right side of the screen to the middle, and at about halfway a giant door will open (animate) in a big starship above the shuttle. If you've played SQ3 you know this scene :)
So far I've had to use "while object is animating wait(1)", but this doesn't work when the shuttle is moving.  Also, I'm moving the shuttle with SetObjectPosition, as MoveObject is way too fast.

I'm a beginner, but have prior knowledge of Java, VB and Pascal, so hit me with all your scripting :)
Any help is appreciated!

strazer

You know you can set the speed when using MoveObject?

Quote
while object is animating wait(1)

Animating != Moving
You would have to use IsObjectMoving:

Code: ags

  MoveObjectDirect(0, 160, GetObjectY(0), 1); // move object to middle of room
  while (IsObjectMoving(0) == 1) Wait(1); // wait until object is has stopped moving
  // at this point the object has arrived
  // do your stuff, animate door and so on


If this is still too fast for you, do it like this:

Code: ags

  while(GetObjectX(0) > 160) { // while object has not arrived in middle of room
    SetObjectPosition(0, GetObjectX(0) - 1, GetObjectY(0)); // move object 1 pixel to the left
    Wait(10); // wait 250 ms (increase this to slow it down even more)
  }
  // at this point the object has arrived
  // do your stuff, animate door and so on

RestoreGame

Thanks, but I'm sorry to say that it wasn't quite what I was looking for. I'll try to explain a little further  :)
So the hatch is in the middle of screen (x=160), and when the shuttle comes to say x=220 (from the right side of the screen), the hatch will _start_ to open while the shuttle is still moving towards x=160. So the hatch will be open when the shuttle stops.
Hope this makes any sense :)

strazer

Then just put

if (GetObjectX(0) == 220) AnimateObject(1, ...); // if shuttle is at x-position 220, start opening hatch

in the while loop.

RestoreGame

I got it working, but had to change a few things.

// script for room: Repeatedly execute
int i;  //simple counter
while (GetObjectX(1) > 135) { //while the shuttle is not yet at the center of screen
   SetObjectPosition(1,GetObjectX(1)-1,GetObjectY(1)); //move shuttle
   if ((GetObjectX(1) < 200) && i < 5) { //if passed this point, the door will open
     i++; //next frame
     SetObjectFrame(0,4,0,i); //set the frame
   }
Wait(3);
}

As you can see, I replaced AnimateObject with setObjectFrame. The animation simply wouldn't start othervise until the pod had stopped. Weird.  ???
Anyways, thank you for your help!  :)

thumtron

Hi there!

I haven't really got a problem, just a little question about object moving. Normally, objects use the walkbale area mask, right? I tried to mark the path the object should take with a special walkable area mask, but it just wouldn't move. So you just have to animate the whole animation, right? And there is no way to let the object move along a specific path, using the walkable are mask?

TerranRich

#13
People:

If an object is being thrown, why not encapsulate the entire animation in one big area, and not have it move at all? Like strazer said, animating is not the same as movign, so why not try stopping it from moving and just have it animate while standing still in place? Like so:

[ . . . . . . . .] => [ . . . . . . . .] => [ . . . . . . . .] => [ . . . . . . . .] => [ . . . . . . . .]
[ . . . . . . . .] => [ . . . . . . . .] => [ . . . o. . . .] => [ . . . . . . . .] => [ . . . . . . . .]
[ . . . . . . . .] => [ . o. . . . . .] => [ . . . . . . . .] => [ . . . . . o. .] => [ . . . . . . . .]
[.o . . . . . . ] => [ . . . . . . . .] => [ . . . . . . . .] => [ . . . . . . . .] => [ . . . . . . .o]

The animation sprites would take up the entire area that is covered by this throwing, as opposed to:

. . . . . . . . . => . . . . . . . . . => . . . . . . . . . => . . . . . . . . . => . . . . . . . . .
. . . . . . . . . => . . . . . . . . . => . . . .[o] . . . => . . . . . . . . . => . . . . . . . . .
. . . . . . . . . => . .[o] . . . . . => . . . . . . . . . => . . . . . [o]. . => . . . . . . . . .
.[o] . . . . . . => . . . . . . . . . => . . . . . . . . . => . . . . . . . . . => . . . . . . .[o]

...having the object itself move. Do you guys understand what I mean?

If this wasn't at all what you were looking, or if this didn't help at all, then just ignore it. I most likely misunderstood.
Status: Trying to come up with some ideas...

SMF spam blocked by CleanTalk