Jump to content

How would I trigger an animation from a still figure?


 Share

Recommended Posts

I have bodies embedded in walls and I want them to animate when the player gets near - how would I trigger the animation and what settings does the model need to have for it to work?  Do I need to use the flowgraph for this?

Mike

MSI Dominator Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 980 GTX with 16gb vram / SSD drives

MSI Dominator Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 1060 GTX with 8gb vram / SSD drives

Alienware Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 1070 Ti with 16gb vram / SSD drives

My Patreon page: https://www.patreon.com/michaelfelkercomposer

My music for sale: https://www.tgcstore.net/category/513?format=all&perpage=30&textures=undefined&price=all&order=default&artists[]=87213

Custom synths and sounds - http://www.supersynths.com

Link to comment
Share on other sites

Regarding this and your other questions, I recommend you go through the official tutorials if you haven't allready. Then, look from youtube some tutorial videos about lua scripting. I recommend for example Aggrors Project Saturn video series, I learned a ton from them, how scripting works, and I have good foundation to learn more. I was complete lua noob and new to modern game design until earlier this year.

So best advice, start going through some tutorials and soon you have an idea how to apply thinhgs you've learned in your own project.

Link to comment
Share on other sites

I've actually read through all the tutorials and no, they do not provide answers for my questions.

I also can program in lua, and many other languages, but sometimes I don't know how software does what it does - this is all very custom.  Hence why I ask questions and hopefully someone helps me out.

While I appreciate your answer, I am sick to death of people telling me to watch this and read that.  I have been programming for over 30 years and while my specialty is mainly web-based and database programming, I think i'm smart enough to figure many things on my own if they make sense to me.

None of my questions' subject matter make sense to me, which is why I ask them. In fact, the questions on the rodents and this one are very similar, so one answer would, in affect, answer both more than likely.

So, if anyone can tell me how to trigger the PlayAnimation command when I get near a humanoid figure, I would be very appreciative.

Mike

MSI Dominator Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 980 GTX with 16gb vram / SSD drives

MSI Dominator Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 1060 GTX with 8gb vram / SSD drives

Alienware Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 1070 Ti with 16gb vram / SSD drives

My Patreon page: https://www.patreon.com/michaelfelkercomposer

My music for sale: https://www.tgcstore.net/category/513?format=all&perpage=30&textures=undefined&price=all&order=default&artists[]=87213

Custom synths and sounds - http://www.supersynths.com

Link to comment
Share on other sites

Sorry. Did not mean to upset you. Regarding the question, in editor, create cube that covers the area where you want to trigger the animation or other event. Then in cubes appearance tab, choose invisible material and from physics tab, select collision type to be trigger. Then create lua script, when player collides with cube, animation is played.

Link to comment
Share on other sites

As you can probably imagine there are probably a few ways to do this and it probably depends on your exact situation. 

Ultimately you probably want a flexible prefab (so you drag and drop it in and it of some sort with a flexible script but initially I'm thinking the flowgraph method may get you started quickest, particularly if you are prototyping (thought some people ultimately find the flowgraph frustrating or limited to use). It's a bit like very simple UE4 blue prints.

A few notes to hopefully get you going down the flowgraph route....

Get your model imported and setup the animation sets on it (you may need to split up a single animation into it's frame ranges, e.g. idle = 0-32, death=33-64 etc.)

Create a map and drop your model in

Create a new script for the model which has a flowgraph exposed input method that can be called to start an animation. 

Add a CSG box to the map enclosing the area you want to trigger the animation - The script can be a modified version of an entry/exit detection script (http://leadwerks.wikidot.com/wiki:collision-enter-exit) that calls a flowgraph exposed output method. Set the CSG with the trigger material and set the physics to rigid body and trigger.

So now you have your model in the map with a script on it, your CSG in a map with a script on it.  

Now for the flowgraph bit.

Drop the model from the scene into the flowgraph and drop the CSG box in as well. You should then be able to connect them up.

Note, it is possible to pass parameters via flow graph called methods though this is not documented so well. (try multi-level lift asset in work-shop).

It is possible to solve the issue in code and ultimately this may be the way to go. You can GetValue SetValue to a build in table as a simple property storage or set up properties on scripts.  You can then scan up parents and down children to locate items that expose a GetValue, script property or method and then call it.

Lua tables provide simple structures that can approach OO but also allow very loose typing so non-similar things can be checked for property/method exposure and if they have it you can call it without having to compose object hierarchies. For game dev this looseness can be handy. As your game gets more complex something more structured may be useful.   See recent discussions of events raising perhaps. 

The FPS Controller and Weapon related scripts provide a lot of information/clues on how to implement a medium complexity setup with objects talking to each other, spawning new items (bullets, debris etc.), testing method existence, having a prefab accept another prefab as an item it will use to talk to etc.

This info may have helped or made things much more complicated.   Hopefully the former.

 

 

Link to comment
Share on other sites

Thank you guys - THAT'S WHAT I NEEDED.  Armed with either method, I can get this accomplished.

New question:  is Tesselation working and what can be done with it?

What I mean is, I'd love to do a few horror elements found in some games and I wonder if tesselation is a way to do it.

I want to make walls breathe in some corridors and I would like silhouettes to move along wall textures trying to get out - think of hands and bodies making the wall textures stretch OUT toward the player - can this be done with tesselation?

Mike

MSI Dominator Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 980 GTX with 16gb vram / SSD drives

MSI Dominator Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 1060 GTX with 8gb vram / SSD drives

Alienware Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 1070 Ti with 16gb vram / SSD drives

My Patreon page: https://www.patreon.com/michaelfelkercomposer

My music for sale: https://www.tgcstore.net/category/513?format=all&perpage=30&textures=undefined&price=all&order=default&artists[]=87213

Custom synths and sounds - http://www.supersynths.com

Link to comment
Share on other sites

Unsure if tesselation fits your need. I think you probably can displace a mesh according to what you want to do but if it was me I'd probably do it in a more scripted and limited fashion so it only looks like the effect of what you are going for.  I would have only limited locations where an animated fbx model was placed in location in the wall and textured and animated as if it was coming out of the wall. If only for effect then a simple approach may work. If a key mechanism of the game that may need to work all over the place then maybe not.


Decals work well for things projected onto walls.  Unsure if they can be animated but probably. Just thinking/typing out loud and this probably won't work but if you can hook up a camera to render to a texture you might be able to somehow record a 3d entity moving and project a processed version (e.g. alpha where 3d model not colouring image) on to an animated decal.   Never tried anything like that but most of the bits are there (render camera to texture etc.), but unsure if it all joins up.

Personally I'd probably try and fake it first with animated custom fbx models/decals done in 3D package .

 

Link to comment
Share on other sites

Hi guys.  What is wrong with this:

Quote

function Script:Collision(entity)

--Play an animation
self:PlayAnimation("screaming",0.05,500,1)

end

 

I have this as a lua script. If you walk up to a figure, it's supposed to animate as a one-shot.  There is only one animation - 0 - called "screaming"

I get the following error when you walk up to the figure:

Quote

Script Error

attempt to call field 'PlayAnimation' (a nil value)

Line 4

 

What am I doing wrong?

Mike

MSI Dominator Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 980 GTX with 16gb vram / SSD drives

MSI Dominator Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 1060 GTX with 8gb vram / SSD drives

Alienware Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 1070 Ti with 16gb vram / SSD drives

My Patreon page: https://www.patreon.com/michaelfelkercomposer

My music for sale: https://www.tgcstore.net/category/513?format=all&perpage=30&textures=undefined&price=all&order=default&artists[]=87213

Custom synths and sounds - http://www.supersynths.com

Link to comment
Share on other sites

There have been recent changes in playing animation which if you're following an older example may cause confusion.  

I think the entity (not script) now has methods for PlayAnimation whereas before it was sort of inherited by the script iteself by an include.

Try

--Play an animation
self.entity:PlayAnimation("screaming",0.05,500,1)

https://www.leadwerks.com/docs?page=API-Reference_Object_Entity_PlayAnimation

 

self in a script refers to the script.  A script attached to an object can access the object as self.entity.

I think that's correct anyway.

(Actually I thought the old methods were still available, but it might depend on if the script you're doing this in is not including the old stuff anymore).

 

 

  • Upvote 1
Link to comment
Share on other sites

Thank you.  That worked perfectly. Now to attach a scary sound/scream to that animation.

Mike

MSI Dominator Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 980 GTX with 16gb vram / SSD drives

MSI Dominator Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 1060 GTX with 8gb vram / SSD drives

Alienware Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 1070 Ti with 16gb vram / SSD drives

My Patreon page: https://www.patreon.com/michaelfelkercomposer

My music for sale: https://www.tgcstore.net/category/513?format=all&perpage=30&textures=undefined&price=all&order=default&artists[]=87213

Custom synths and sounds - http://www.supersynths.com

Link to comment
Share on other sites

You'll probably find it useful to have a project set up (even if a different project to the one you are mainly working on) with the FPS sample as it's base template. 

It is usually very up to date with current changes so if something not working maybe search that whole project with a text editor and there's a good chance it'll find your command in use in the current method with a good working example.  

Not saying it'll solve everything but might save a few minutes. 

The API docs have had recent work to so should be quite current and almost always have an example that gets you going.

For some things it is even worth having a second main script that you switch between that sets up a very simple code based world as some examples take it from this point and you can usually just cut and paste the chunk in and see the example working straight away in simplified world.

 

 

  • Upvote 1
Link to comment
Share on other sites

Ok, so here is my script:

Quote

function Script:Start()
    --Load a sound
    self.sound = Sound:Load("Sound/Characters/demonscream_mono.wav")
end

function Script:Collision(entity)

--Play an animation
    self.entity:PlayAnimation("screaming",0.05,500,1)

        if self.sound then
            --self.sound:Play()
            self.entity:EmitSound(self.sound,50,0.002,1,false)
        end

end

function Script:Release()
    --If the sound was loaded, release it now and set the variable to nil
    if self.sound then
        self.sound:Release()
        self.sound = nil
    end
end

 

So, it works, but it seems to loop the sound despite the boolean loop set to false.

Also, what is the difference between play() and emitsound?

If I use the self.sound:Play() then the volume is awfully loud! I cannot seem to set the volume or I am not doing it right.

The other command I can alter the volume but it seems to play it looped and temporally slow. I need to play as intended.

It's a roughly 8 second mono 44.1khz 16 bit wav file.

How can I use the self.sound:Play() and lower it's volume to say, 10% as a one-shot, not looped? How can it get softer in volume as the player moves away from the entity that the sound played from?

Mike

MSI Dominator Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 980 GTX with 16gb vram / SSD drives

MSI Dominator Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 1060 GTX with 8gb vram / SSD drives

Alienware Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 1070 Ti with 16gb vram / SSD drives

My Patreon page: https://www.patreon.com/michaelfelkercomposer

My music for sale: https://www.tgcstore.net/category/513?format=all&perpage=30&textures=undefined&price=all&order=default&artists[]=87213

Custom synths and sounds - http://www.supersynths.com

Link to comment
Share on other sites

I think EmitSound *IS* probably what you want.  I think Play is usually too simplistic for most cases.   

that it's playing slow and stopping makes it sound like the parameters are not aligned and it is maybe taking the 0.002 as pitch and the 1 as false. Could be an area things are out of sync slightly between beta and docs.

Maybe try setting the 0.002 to be 1 assuming it's pitch and the 1 to be false or 0 and seeing if it stops the looping?

Also make sure you're not accidentally triggering it again (I've had that and it can sometimes make the sound seem strange - maybe like it is not the right rate). 

Simplify with a simple code based world (using a renamed main file) that response to a key press and literally just plays a previously loaded sound on a sound source. Rule everything out, otherwise it can get pretty confusing introducing new commands in a complex world. At least it helps my brain :)

 

 

 

 

 

 

Link to comment
Share on other sites

  • 5 years later...
On 7/2/2017 at 5:41 PM, Core said:

Regarding this and your other questions, I recommend you go through the official tutorials if you haven't allready. Then, look from youtube some tutorial videos about lua scripting. I recommend for example Aggrors Project Saturn video series, I learned a ton from them, how scripting works, and I have good foundation to learn more. I was complete lua noob and new to modern game design until earlier this year.

So best advice, start going through some tutorials and soon you have an idea how to apply thinhgs you've learned in your own project.

Shame aggror tutorial videos must been removed.. Not on his YouTube channel anymore. 

Dream since child of making games! From Game Programming Starter Kit 3.0, Blitz Basic, Map Creation since Duke 3D, Game Maker, Blitz3D (of recent..2023) and many other engines and years..... never really sticking to it with inner struggles that I've had to fight along with pushing to learn and acheive.

40 years old.. came across Leadwerks on Steam... Learning slowly but surely and loving it!

Learn with me or just watch me fail! at my random Youtube Channel, as I stream adhoc while learning and using LeadWerks and other game creating tools.

https://www.youtube.com/@wazmeister3151/featured

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...