object stops moving when player changes room

Started by fitbo, Mon 13/03/2006 21:21:02

Previous topic - Next topic

fitbo

Hey, I have a problem when the player changes the room. When the player changes the room at the moment a car is passing by, the car remains at the same place as before, when the player returns to the room. The car is  an object, here' s the script:

// script for Room: First time player enters room

object[3].Visible = true ;
object[3].SetView(8,0) ;
object[3].SetPosition(-300,210) ;
object[3].Solid =1;

// script for Room: Repeatedly execute

timer++;

if (timer ==40)
object[3].Animate(0, 3, eRepeat, eNoBlock, eForwards);
if (timer ==100)
object[3].Move(400, 210, 7, eNoBlock, eAnywhere);

  // script for Region 1: Player walks onto region

player.ChangeRoom(2,110,105);

Thanks for help!


DoorKnobHandle

Hello and welcome to the forums first. :)

Your object will not be handled (moved in your case) if the player is not in the current room, because you have a rooms rep_ex function is only called if the player is in the room.

So, to fix your problem, you'd probably have to think about things differently. In order to help you with that, we'd need to know how exactly you want it to work. You could change the position of the whenever the player enters the room (as you do with the first time player enters room at the moment).

Sorry if this isn't much helping, I'd be glad to give you a suggestion if I'd know more!

EDIT: I think I just got you. Do you just want to make this car disappear when the player returns to the room the second or third (etc) time?

fitbo

Yes the car has to disappear. But the thing is : we want the time to run continously, so that if you're outside of a house and a car is passing by, and you enter the house and rapidly come out again, the car would still be finishing his movement

thx for your attention

Shini

Did you try to use a character instead of an object for your car, since a character can   travel trough rooms?

fitbo

If I change the car to a character doesn't work either. The car is still at same position when the player reenters the room. 

Ashen

#5
It might be overkill for one simple effect, but what about using the Character Control Module? As I understand it, it'll let you move characters that are in other rooms, which sounds like what you need.

Or, what if you make timer global, and altered in the global repeately_execute so it continues to change when the player isn't in that room, and alter the car object's position along it's path based on timer in 'Player enters room (before fadein)'? E.g. (untested):
Code: ags

if(timer < 100) object[3].SetPosition(-300,210) ; // Initial position
else if (timer < 120) object[3].SetPosition(-250,210) ;
else if (timer < 140) object[3].SetPosition(-200,210) ;
//Etc...


And, you might need to alter the rep_ex command, so that it'll restart the object moving when you re-enter the room, e.g.:
Code: ags

if (timer >= 100 && object[3].Moving == false) object[3].Move(400, 210, 7, eNoBlock, eAnywhere);
I know what you're thinking ... Don't think that.

fitbo

One problem is solved, namely that the car has disappeard when the player reenters the room, but there is another problem; the car is passing at speed 1, the player leaves the room, and immediately reenters and the car has disappeared. What can I do to make the car visible and that he still continues moving slowly out of the screen.

I used
 
if (timer >= 100 && object[3].Moving == false)
object[3].Move(400, 190, 7, eNoBlock, eAnywhere);

in the global script to make the car disappear when the player reenters rhe room,but I don't quite get it what you want to do with the

if (timer <100)object[3].Setposition(-300,190);
if (timer <120)object[3].Setposition(-250,190);



Ashen

#7
This bit needs to be in the ROOM SCRIPT, of the room the car is in:
Code: ags

if (timer >= 100 && object[3].Moving == false)
object[3].Move(400, 190, 7, eNoBlock, eAnywhere);


Otherwise, in   the Global Script, it'll move object[3] in every room (or give an error if there isn't one).

This bit:
Code: ags

if (timer <100)object[3].SetPosition(-300,190);
else if (timer <120)object[3].SetPosition(-250,190);
//Etc...


would go in the 'Player enters room (before fadein)' interaction. Basically, I meant use how far over 100 the timer variable is (timer ==100 being when it starts moving) and set the car obejct's position based on that, so it looks like the car was moving while the player was out of the room. You'd need to figure out how long the object takes to complete the move, and from that about how far along it should be at given timer intervals - e.g. the example assumes it move 50 pixels (from - 300 to -250) in 20 game loops.

EDIT: Just to check I actually understand the problem:
You have a 'Car' (object 3) in a room, at (-300, 190). When a variable (timer) reaches 100 you want the Car to start to move toward (400, 190). That's the simple bit.
You also want it that the Car will continue moving while the player isn't in the room - so that if they go to room 2 and come back after a few seconds, the car will as far along it's path as it would have been had they stayed in the first room, watching it move for the same length of time.
Is that about right?
I know what you're thinking ... Don't think that.

fitbo

#8
Yeah, that's right, you've understand the problem. I'm gonna try it now...

EDIT:
Yeah, thanx it worked Grin

but isn' t ther an easier way to write it, instead of

if (timer <110)
object[3].SetPosition(-340,200);
else if (timer <120){
object[3].SetPosition(-330,200);
}
else if (timer <130){
object[3].SetPosition(-320,200);
}
etc

Ashen

#9
Well, if you're happy for it to be one pixel per loop, you could do it:

Code: ags

if (timer > 100) object[3].SetPosition(timer-450,200);

Since -350 + (timer - 100) = timer -450

If you want a speed other than 1 pixel/loop, you can probably figure out some equation that'd work.

You'll probably also want to put an upper limit on it, e.g.:
Code: ags

if (timer > 100 && timer <= 850) object[3].SetPosition(timer-450,200);

(Since 850 - 450 = 400, the final x coordinate.)
I know what you're thinking ... Don't think that.

fitbo

Stupid question: How do I write another equation, if I want a different speed?

Ashen

#11
You'd just need to change the timer-450 bit to reflect how much you want it to move.

E.g.:
2 pixels per loop would be
-350 + ((timer-100)*2)
OR:
((timer-100)*2) - 350
(timer - 100) gives the number of loops it should've been moving for.
*2 doubles it (obviously), for 2 pixels of movement per loop passed.
-350 is the starting x coord.

One pixel per 2 loops would be
((timer-100)/2) - 350

So, for example:
Code: ags
if (timer > 100) object[3].SetPosition(((timer-100)*2) - 350 ,200);


You can replace the 2 with any value, to make it as fast or slow as you like.
It probably won't be perfect, but it should be a reasonable enough approximation.

EDIT:
If you added the upper limit I suggested, you'll also need to change that.
I know what you're thinking ... Don't think that.


SMF spam blocked by CleanTalk