Rick Posted January 9, 2014 Share Posted January 9, 2014 Was going over some of my LE 2 videos and found this one where I tried to create an in-game cut-scene. This was all done in Lua using coroutines (a Lua feature). I'll have to see in coroutines work in LE 3.1 version because they would allow you to call functions in sequence where they would yield which would continue the main game loop, and come back where they left off each frame. Allowing you to make scripts like: function MyCutScene() GoToPoint(0, 0, 0) SwitchCamera(camera1) PlaySound("speech") GoToPoint(10, 0, 10) end Where GoToPoint() would move a little to the destination, then yield back to the main game loop to show the change, then go back where it was in the function from last frame, and move a little more. It wouldn't actually exit this function until it reached it's point, and then it would go into the other function and switch camera, etc. This is sort of the way we think about in-game cut-scenes, but without coroutines we end up with a ton of booleans and if statements to manage the state of things, which is a mess. 2 Quote Link to comment Share on other sites More sharing options...
Arinthian Posted January 9, 2014 Share Posted January 9, 2014 Wow, that looks really cool. I'd love to see/use something like this in LE 3.1 looks like I may have to read up on coroutines Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 9, 2014 Share Posted January 9, 2014 Sweet Rick. I didn't even know Lua had coroutines. That is so useful! Quote Link to comment Share on other sites More sharing options...
Rick Posted January 9, 2014 Author Share Posted January 9, 2014 Looks like they do work with Leadwerks Lua. Now it's just creating some functions that do common things with the yeild in them. I can think of: GoToPoint(), which I know what you're thinking, we already have one of these in LE, but this one would just check that the entity is at it's destination before returning because in a cut-scene you may want to not continue until an entity moved to a position. I feel like we can make "blocking" functions and "async" functions to be used in coroutines for cut-scenes. Async functions do something and return right away, while blocking don't return (still yields of course) until a condition is met. GoToPoint() -- this can be used to move the camera around to different pivots that were setup in the scene GoToPointAsync() -- probably used mostly to move actors around over time (the built-in Follow() and GoToPoint() would be used here as the engine handles updating them every frame PointAt() -- this can be used for cameras to instantly point at other entities PointAtAsync() -- cameras could use this also to slowly pan over time to a point PlaySound() PlaySoundAsync() PlayAnimation() -- could really only be used for non looping, 1 time, animations since it would need a finishing point PlayAnimationAsync() -- would start playing an animation but return right away. we'd need a general animation manager that is being called in some update statement Wait() -- would return after waiting x ms. doesn't really make sense to have an async version of this With functions like these I think we could do some pretty cool cut-scenes. I would thinking we could make 1 entity script that takes a parameter that specifies a Lua file that holds a function, and a parameter that has the function name in that file. This function would end up being global but each cut-scene is global to the game anyway so the name of the cut-scenes will need to be unique. Now that I'm typing maybe the name doesn't as we don't play more than 1 cut-scene at a time. Another parameter would be to enable/disable the cut-scene. In the cut-scene entity script we should be able to import the lua file specified as the parameter from the editor. We could create that coroutine using it's function name that was the other parameter in the Start() function. Then when the Enabled input function is raised, it would set a bool that would resume the coroutine each frame in the Update() function. That would call the users lua script which will be calling the coroutine specific functions which have the yield statement in them. I think this just may work Quote Link to comment Share on other sites More sharing options...
Tim Shea Posted January 10, 2014 Share Posted January 10, 2014 This would actually be pretty useful for general gameplay programming, not just cut scenes. This is the type of behavior that is typically provided by custom scripting engines when they are developed for games. For instance, for programming "smart" animations, where the animation automatically generates particles, does damage, plays sounds, etc. during playback, this system would be very useful. If you'd like any help working on this, I'd be interested. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.