Game Development Community

How do I start a sequence on game load?

by Joel Schilling · in Verve · 10/24/2009 (8:28 pm) · 11 replies

I have a sequence where my villager walks a loop in the village, and everything works well (thanks for the fix!)

However trying to get it loaded automatically is a bit of a different story. I added the following to PLAYERDATA:onAdd() in the server scripts:

%controller = new VController();
%controller.readFile("scripts/Walking.vsf");
%controller.play();

The animation plays and the gizmo moves (if you have her selected) but she walks in place.

I'm assuming I'm probably trying to initialize and play the sequence at the wrong place, but I am not sure where is the correct place to put this code.

#1
10/25/2009 (6:32 am)
The code you've got there should work perfectly. The only question is where should it be placed?

I don't think there is going to be a be-all-and-end-all solution to playing a sequence at the beginning of the mission, as it will depend on what the sequence is doing. It really is a troublesome problem, because some of the required data (say for example, path node data) can be sent *after* the mission has loaded.

Your best bet would be to create and execute the sequence on the server some time after the entire mission has been loaded and not in PlayerData::onAdd(). Look for the function, startGame() (inside scripts/server/game.cs) and try placing it at the end of that method.

Give that a whirl and let me know how you get on. If that doesn't work, I'll have to have a better look at it.

Thanks for bringing this up Joel, another little thing I didn't think too much about!
#2
10/26/2009 (5:14 pm)
Nope, when I move that code into startGame(), the Gizmo still starts walking the path, leaving the NPC standing there. If I make a function with the code in it, and call the function from the console, everything works as intended. I really need to get my head wrapped around where the NPC schedules should be executing. For a cutscene, I would think we would want it all to to be on the client side, but for NPC schedules, we would want it to execute on the server, with updates being sent to the client. I don't understand Verve architecture enough to know exactly what should be going on.

Is using Bezier computationally intensive? It seems as she get halfway through her path she starts slowing down and the game becomes laggy.
#3
10/26/2009 (6:18 pm)
I just tried placing the call in GameConnection::startMission, and it works a treat. Generally, the server should handle everything. Torque is pretty finiky about who has control over what object, so executing a cutscene on the client may not actually do anything. It is a pretty tricky problem.

Bezier curves are more intensive than a linear path, though if you feel they are doing do many calculations you can reduce the precision of the curve by changing the "gBezierInterpStep" at the top of VPath.cpp. The way I've gone about the calculations while an object is pathing on it should reduce the amount of work being done though.

Slowing dow and laggy? I'm not sure what is going on there, it doesn't sound like the bezier calculations would do that. Must be something else acting up.
#4
10/26/2009 (6:19 pm)
Just to clarify, this is what I ended up with:
function GameConnection::startMission(%this)
{
   // Inform the client the mission starting
   commandToClient(%this, 'MissionStart', $missionSequence);

   %controller = new VController();
   %controller.readFile("sequences/TestActor.vsf");
   %controller.play();
}
#5
10/26/2009 (7:37 pm)
OK, that worked for me. Not being able to play client cutscenes could be problematic for some... thankfully I am doing a single player game, so it makes no difference to me.

I think I was confusing two different issues with lag. I think I got a major slowdown because I ran the function multiple times against the same NPC. But there is another issue--Along the path sometimes the NPC starts slowing down and "sliding" and then jetting off. I noticed the slowdown occurs when there is a short distance between two points, and the speedy parts are when the next point is far off. I expect when I import a path to the motion track at a speed of .5, that the length from from one node to the next will have the correct proportionate time to keep the walking speed the same.

Interestly enough (I am trying to research this as I write) this only happens when you run from the script, and not when you run from Verve editor. Or at least, it is more noticeable from the script.
#6
10/26/2009 (7:44 pm)
I think the "problem" you describe there is one of the attributes of a Bezier curve. When a bezier curve is calculate, you integrate t from 0 to 1 to find the point along the curve at that particular t. The problem here is that the distance 0.00-0.05 it not likely to be the same as 0.05-0.10 despite having the same time delta. Essentially, a bezier curve speeds up on "straights" and slows down on "corners".

There is a way of combating this "feature" and that is to take baby steps on each integration to see how far the object has travelled.

Another thing to take note of with paths in Verve is that the speed that the object travels is based on the distance between each node and the time between each event in the Verve sequence. There is an import tool to help you maintain a constant speed on a predetermined path which may help you out in this instance. To use it, just right click on the Motion Track and click on the import button (I can't remember the label off the top of my head).

Hope that helps somewhat!
#7
10/26/2009 (7:46 pm)
Quote:OK, that worked for me. Not being able to play client cutscenes could be problematic for some... thankfully I am doing a single player game, so it makes no difference to me.
Absolutely it will cause problems! The only way around this would be to have client-only objects (which I don't think Torque likes, I don't know enough about it though) which are used in the sequence.
#8
10/26/2009 (8:30 pm)
Sorry I wasn't more specific. I did use the import tool with a constant speed of .5 to make the motion track. It works beautifully by playing the sequence from the Verve editor (at least I am not able to perceive a difference visually) But when I play the sequence at mission startup, there is a noticeable speedup on the straight part and slowdown on the curves.

If you are taking feature requests... I would like a compromise between linear and Bezier. Bezier does all kinds of loops and sharp angles. I would like a path that has rounded corners, so the NPC doesn't do military turns :) without the loops and sharp switchbacks.

Another suggestion... Since the mounted object doesn't complete the full loop, you might want to consider not drawing the line from the final node back to the starting node. I was a bit confused by it at first, and it still can be a bit confusing at times to distinguish the segment that isn't used. That being said, for sequences with Loop checked, it would be very useful to make that last segment to actually be used.

Sorry if I am being a PITA. I hope you are finding my feedback useful. Thanks again for your quick responses.
#9
10/26/2009 (8:47 pm)
Quote:Another suggestion... Since the mounted object doesn't complete the full loop, you might want to consider not drawing the line from the final node back to the starting node. I was a bit confused by it at first, and it still can be a bit confusing at times to distinguish the segment that isn't used. That being said, for sequences with Loop checked, it would be very useful to make that last segment to actually be used.
Very handy ideas Joel! I'll add them to the list! You're not being a PITA, its nice to see someone using Verve, even at this stage in development.

Thanks mate!
#10
11/05/2009 (2:40 pm)
Philip, have you looked more into why imported paths play at a proportional rate when run from the Verve editor, but not when running them at startup?
#11
11/05/2009 (4:11 pm)
I had a quick look and I cannot see anything obvious jumping out at me. I'll take another look today and see what I can do.

Cheers!