randomdude Posted August 18, 2017 Share Posted August 18, 2017 Hello Guys, I try to make a the opening scene/intro, the most of you know I suck at coding and need some help here. Its probably very easy to solve. So I decided to make a thread where I can ask things about the coding problems. I don´t spam with a lot of threads and I get my things solved. So here we go. I linked a video to the intro, its not finished, so far but I want to get this coding stuff done before I add more details. (18+,mature content) https://www.twitch.tv/videos/168041356 The Dude don´t want to stand up I tried a lot of variations but it wont function. He has extra animations for standing up as well but it would be nice if he just get into the idle position. function Script:Start() if self.entity:GetMass()==0 then self.entity:SetMass(10) end self.entity:SetPhysicsMode(Entity.CharacterPhysics) self.camera = Camera:Create() self.angle = self.entity:GetRotation().y self.cameraangle = self.angle + self.entity:GetCharacterControllerAngle() self.startposition = self.camera:GetPosition() end (..) function Script:UpdatePhysics() local window = Window:GetCurrent() local context = Context:GetCurrent() local cx = context:GetWidth()/2 local cy = context:GetHeight()/2 local newmode local animmode=0 if self.startposition and self.entity:GetAirborne()==false then newmode = "Sit" self.entity:PlayAnimation("Sit",0.035) end --if self.startposition==false and self.entity:GetAirborne()==false then --newmode = "Idle" --self.entity:PlayAnimation("Idle",0.035) --end It´s the normal thirdperson script. In this variation I tried setting self.startposition true and false, but it does make it worse. xD I try to make the animation dependent on the cameraposition. but I could be wrong. I have really no I idea to get this done. If a skilled programmer wanna join my project, it would be better. I hate this coding stuff. I have so many great ideas and already mapped the main location, this is just side stuff because I wanna enjoy myself with doing this graphic things, coding just blocks my workflow. Quote Link to comment Share on other sites More sharing options...
randomdude Posted August 19, 2017 Author Share Posted August 19, 2017 None of this is working. Why? The code does it for KeyDown but not for KeyHit. What is the difference then? if self.entity:GetAirborne()==false and window:KeyHit(Key.E) then newmode = "Idle" self.entity:PlayAnimation("Idle",0.035) else newmode = "Sit" self.entity:PlayAnimation("Sit",0.035) return end if self.entity:GetAirborne()==false and window:KeyHit(Key.E)==true then newmode = "Idle" self.entity:PlayAnimation("Idle",0.035) else newmode = "Sit" self.entity:PlayAnimation("Sit",0.035) return end if self.entity:GetAirborne()==false then if window:KeyHit(Key.E)==true then newmode = "Idle" self.entity:PlayAnimation("Idle",0.035) return else newmode = "Sit" self.entity:PlayAnimation("Sit",0.035) end end if self.entity:GetAirborne()==false then if window:KeyHit(Key.E)==true then newmode = "Idle" self.entity:PlayAnimation("Idle",0.035) end if window:KeyHit(Key.E)==false then newmode = "Sit" self.entity:PlayAnimation("Sit",0.035) end end Quote Link to comment Share on other sites More sharing options...
macklebee Posted August 19, 2017 Share Posted August 19, 2017 You should only look for one specific key hit per update cycle or you will have issues like this. Rework the code to check for the E key's keyhit only once. previous discussion: Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
randomdude Posted August 19, 2017 Author Share Posted August 19, 2017 Its one, I just made four different varations of it. function Script:UpdatePhysics() local window = Window:GetCurrent() local context = Context:GetCurrent() local cx = context:GetWidth()/2 local cy = context:GetHeight()/2 local newmode local animmode=0 if self.entity:GetAirborne()==false then if window:KeyHit(Key.E)==true then newmode = "Idle" self.entity:PlayAnimation("Idle",0.035) else newmode = "Sit" self.entity:PlayAnimation("Sit",0.035) end end I thought the GetAirborne does interfere so I changed it to this. Documentation says " Returns true if the specified key is has been pressed since the last time it was checked, otherwise false is returned." Maybe its this? The dude goes up a bit but gets down if you release the key. It works with KeyDown but I dont want the key pressed all the time. Quote Link to comment Share on other sites More sharing options...
Genebris Posted August 20, 2017 Share Posted August 20, 2017 You start playing animation in the frame when key is hit. In the next update you start playing sit animation. Quote Link to comment Share on other sites More sharing options...
Phodex Games Posted August 20, 2017 Share Posted August 20, 2017 I have a question and an answer to this topic. Is there any reason you call you stuff in the UpdatePhysics function, because I see no reason for that. Correctly me if I am wrong as I am no expert. If I can give you an advice, built in a system allowing you to perform keychecks multiple times per Update. I use this method as well, I would implement it as fast as possible into your project. Works like the following: --Put this into your main.lua: --main.lua code here keyHit = {} --just declare this variable, outside the main loop --some more main.lua code --Put this inside the main loop in the main.lua file: --------------------Hit --Mouse keyHit.RMouse = window:MouseHit(2) keyHit.LMouse = window:MouseHit(1) --Alphabetic keyHit.A = window:KeyHit(Key.A) keyHit.B = window:KeyHit(Key.B) keyHit.C = window:KeyHit(Key.C) keyHit.D = window:KeyHit(Key.D) keyHit.E = window:KeyHit(Key.E) keyHit.F = window:KeyHit(Key.F) keyHit.G = window:KeyHit(Key.G) keyHit.H = window:KeyHit(Key.H) keyHit.I = window:KeyHit(Key.I) keyHit.J = window:KeyHit(Key.J) keyHit.K = window:KeyHit(Key.K) keyHit.L = window:KeyHit(Key.L) keyHit.M = window:KeyHit(Key.M) keyHit.N = window:KeyHit(Key.N) keyHit.O = window:KeyHit(Key.O) keyHit.P = window:KeyHit(Key.P) keyHit.Q = window:KeyHit(Key.Q) keyHit.R = window:KeyHit(Key.R) keyHit.S = window:KeyHit(Key.S) keyHit.T = window:KeyHit(Key.T) keyHit.U = window:KeyHit(Key.U) keyHit.V = window:KeyHit(Key.V) keyHit.W = window:KeyHit(Key.W) keyHit.X = window:KeyHit(Key.X) keyHit.Y = window:KeyHit(Key.Y) keyHit.Z = window:KeyHit(Key.Z) --Numeric keyHit.D0 = window:KeyHit(Key.D0) keyHit.D1 = window:KeyHit(Key.D1) keyHit.D2 = window:KeyHit(Key.D2) keyHit.D3 = window:KeyHit(Key.D3) keyHit.D4 = window:KeyHit(Key.D4) keyHit.D5 = window:KeyHit(Key.D5) keyHit.D6 = window:KeyHit(Key.D6) keyHit.D7 = window:KeyHit(Key.D6) keyHit.D8 = window:KeyHit(Key.D7) keyHit.D9 = window:KeyHit(Key.D8) --Special keyHit.BackSpace = window:KeyHit(Key.BackSpace) keyHit.CapsLock = window:KeyHit(Key.CapsLock) keyHit.Space = window:KeyHit(Key.Space) keyHit.Escape = window:KeyHit(Key.Escape) ----------------------------------------------- You can do the same for KeyDown of course. Now instead of "if window:keyHit(Key.E) then" you can use "if keyHit.E then". This is not only shorter, but also can be used as often as you want. Note that you need to add some characters to my keyHit list, because mine is not complete. I hope this is understandable if not I could provide a modified main.lua including my code so you can take a look at it. About your actual problem, as far as I understood you just want the person to stand up if you press E. The problem is that it just plays the animation as long as keyHit is true and that is just the case for one millisec maybe. So here is the fix: if self.entity:GetAirborne()==false then if window:KeyHit(Key.E) and newmode ~= "Idle" then newmode = "Idle" self.entity:PlayAnimation("Idle",0.035) end end Now the entity plays the idle animation if you hit E. The question under which circumstances you want the entity to sit? You have to code this externally, not within the KeyHit command! Quote Link to comment Share on other sites More sharing options...
randomdude Posted August 20, 2017 Author Share Posted August 20, 2017 Okay I skip this with the table at the moment, but thanks for the idea. But this question was good, I have no idea I just thought I have to place it there. I put the Sit animation here. function Script:Start() if self.entity:GetMass()==0 then self.entity:SetMass(10) end self.entity:SetPhysicsMode(Entity.CharacterPhysics) self.camera = Camera:Create() self.angle = self.entity:GetRotation().y self.cameraangle = self.angle + self.entity:GetCharacterControllerAngle() newmode = "Sit" self.entity:PlayAnimation("Sit",0.035) end The KeyHit command here. function Script:UpdatePhysics() local window = Window:GetCurrent() local context = Context:GetCurrent() local cx = context:GetWidth()/2 local cy = context:GetHeight()/2 local newmode local animmode=0 if self.entity:GetAirborne()==false then if window:KeyHit(Key.E) then newmode = "Idle" self.entity:PlayAnimation("Idle",0.035,0,0) end end It its working, he finally stands up, but all following animations like walk etc. demand now the keyhit. to stop and the idle animation is ignoring my speed value. I tried to make the whole movementbody dependent on the keyhit to activate but its not working. This could be a solutions because I dont have to rework all movementcommands. Any idea? Here is this keyhits = 0 thing. but I dont understand how to use it, maybe it declares how many hits? https://www.leadwerks.com/learn?page=API-Reference_Object_Window_KeyHit Or should I make this with an event? because I want a textbox with some monolog and after it is read "press e" and he stands up. Thats the whole idea there. I made a video again, Intro2 https://www.twitch.tv/videos/168446210 Thanks you all so far. Quote Link to comment Share on other sites More sharing options...
Phodex Games Posted August 21, 2017 Share Posted August 21, 2017 Actually to be honest I dont use the built in PlayAnimation command, so I dont have much experience with it. I use my self made animation manager. Maybe I will put this on the workshop any time soon, because it provides more features then the build in animation function. I cant tell you for sure why its ignoring your speed value, because you did not provide the code where your char is playing the running animation. What I mentioned is that you need some blending when your character stands up its a little bit direct. To make your character go idle when you dont move, as this is what I understood you want to realise, you need to check if your character has speed in any direction, or if the play is pressing any kind of key. So you have to come up with something like this: local speed = self.entity:GetVelocity(true) local newMode = nil if speed.x == 0 and speed.y == 0 and newMode ~= "Idle" then newMode = "Idle" self.entity:PlayAnimation("Idle", 0.035) elseif newMode ~= "Walking" then newMode = "Walking" self.entity:PlayAnimation("Walking", 0.035) end Notice that you need to check if your mode is "Idle" or "Walking" already that your entity does not call "PlayAnimation" all the time this is very important. It can be pretty complicated if you have many diffrent modes, because you need to notice any circumstance there is and how it affects your mode. I would recommend you creating a seperate function for your modes this can look like this: function Script:SetIdle() newMode = "Idle" self.entity:PlayAnimation("Idle", 0.035) end function Script:SetWalking() newMode = "Walking" self.entity:PlayAnimation("Walking", 0.035) end Or like this: function Script:SetMode(mode) newMode = mode if mode == "Idle" then self.entity:PlayAnimation("Idle", 0.035) end if mode == "Walking" then self.entity:PlayAnimation("Walking", 0.035) end end This makes it easier for you and you have your code more organized. You also most likley need to set the modes more than just one time where this helps you as well. Its a little off topic, but because I am currently creating a framework, including many systems, like the animation manager, an easy UI system, AI and so on, I mentioned this would be very helpful for you as you dont want to code that much, and thats exactly the reason I am creating it. Unfortunately there is a lot of work to be done and a release can't be expected any time soon, but maybe I will provide some smaller parts in the workshop in the future. Quote Link to comment Share on other sites More sharing options...
randomdude Posted August 22, 2017 Author Share Posted August 22, 2017 Yeah Thanks man, I decided to skip this for a while, I tried it but I have no clue how I get this to work.I wil try it later when I have more knowledge about coding. It seems like I have to rework the whole script to get those two animations working, its kinda not worth it. Anyway, where do I get this animationmanagerscript? I dont have it, and can you maybe explain how this "blend" animation-thing is working please? I have no idea how to use this. I´m thinking about another problem at the moment. A script that allows the dude to interact with the world. I just took a function from the fps player script. Here see what happens, its really funny. But it works with a just an empty start function. Works with the NPCs as well. https://www.twitch.tv/videos/168951112 Hmm, I thought I will not make an inventory, items and all this stuff, Its kinda boring for me to make and the player to play. All I need is a function based on that cylinder I made around the dude to interact with E. So I can make for example spots where he activates something like doors, buttons and more importent talking, dialog fields. Any Ideas how to start? Quote Link to comment Share on other sites More sharing options...
Phodex Games Posted August 23, 2017 Share Posted August 23, 2017 Hi, About that animationmanager thing: Well there are a few things to say about it. First, yes Leadwerks has/had an own animationmanager script build in, which was used back in the days, when the "PlayAnimation" function was not available, but I was talking about my own animation manager script I created myself. You cannot download this anywhere as I have not released it :D. However never mind it, as the PlayAnimation function works well and its much easier for beginners. About Blending: PlayAnimation(string sequence,number speed=1.0f, number blendtime=500, number mode=0, string endhook="") This is what you find in the documentation. See that "number blendtime", this is for blending. More precise this is the time in miliseconds to blend form one animation to another as far as I understand it. About your interaction function: Puh, would take a lot of time to indeep explain, how to do interaction, what options you have etc. However as far as I understand you want your player to interact with stuff in the world right? I have no idea how the code, I could see in the video should get this done. Where does this function even get called from? The only thing this lines of code does is to search for entities which have an "Use" function inside their script. The most common way to handle interaction is to use a raycast. I hope you are familiar in any way with that, so I dont have to explain this more detailed :D. Another way I could think of especially in those 3rd person "topdown" like style is a cylinder or sphere around the player which scans if objects around can be ineracted with, but this method may pick more than one Item at once so this could be a problem. However it would be a little bit too complicated to explain this in detail. I think you are doing pretty well so far and your stuff looks interesting. I think one of the fun parts making games is to come up with own ideas and to solve problems like that. I see you dont feel the same way :D, but maybe try it out. I know you want to focus on the art stuff, but give coding a try :). Sit down, enjoy a cup of coffee, take pen and paper and think on how to solve your problem, try it out and see what you can do. Good Luck Quote Link to comment Share on other sites More sharing options...
randomdude Posted August 23, 2017 Author Share Posted August 23, 2017 Hey man, Thanks again, yes that was my question, there is the playanimation stuff so why I need a animationmanager? I got this let me know if you finished your script if you want. Yes I saw this but I have no idea how this is meant. number blendtime=500 thats the time I can set but how do animation one know that animation two has to blend into? I dont understand how is it used. do I have a function like "function blend()" or BlendAnimation or something like that? I have no idea what raycasts are but you dont need to explain this. I will look if I find something in the forums. " The only thing this lines of code does is to search for entities which have an "Use" function inside their script. " I can do do something with this, let me think a while about that. Yeah its fun for me as well, but I want to get it done, it takes just too much time and then it doesnt work. My plan is to finish the maps and do this at the end. I have my skills in mapping and the editor. If you ever have a performance problem or no idea how to give your maps a special touch just let me know. I have not seen something from you but the most people here make lets say a lot of mistakes that make their maps look unprofessional, they then blame the engine and go und ue or unity, but I love the graphics, the sharpness, I have so much fun doing this mapping stuff. I mapped a lot in hammer and world when I was younger. One good tip that most people do wrong is thinking, useing models as mainstructures in your maps make its performance better. but thats not true. Here I made a video for you to see a very importent tip in making maps. https://www.twitch.tv/videos/169168592 Thats one of the most important things. you have to make all sides that can not be seen invisible. So you can maintain optimal performance and make use of the great engine graphics. I just telling you this that its not so one-sided. Have good luck too. 1 Quote Link to comment Share on other sites More sharing options...
Phodex Games Posted August 24, 2017 Share Posted August 24, 2017 Hey, to explain the blending. As I dont use this function very often dont blame me if I am wrong ^^. This is an example code to show the function: function Script:Update() if window:KeyHit(Key.D1) then self.entity:PlayAnimation("Idle", 5, 500) elseif window:KeyHit(Key.D2) then self.entity:PlayAnimation("Walking", 5, 500) end end So what happens now is that if you press "1" on the Keyboard, the entity starts playing the idle animation. Because the entity had no animation before, blending does not matter. Hope thats clear so far. So if you now press "2" then the walking animation gets played, BUT its blends from the idle animation to the new one. More precise: The idle animation needs 500 miliseconds to blend into the walking animation. So the blending always happens you just decide how long it takes, if it is nil or 0 then no blending happens. I hope this was understandable. Of course this works the other way as well if you go from walking to idle. Try experimenting with it. On 23.8.2017 at 3:19 PM, randomdude said: Yeah its fun for me as well, but I want to get it done, it takes just too much time and then it doesnt work. My plan is to finish the maps and do this at the end. Its funny because I could say the exactly same thing about art :D. I have that problem with good working animations and models, but I really want to learn it. Currently getting into ZBrush. My Animation skills are at least good enough to create some basic motions. That tip on performance is very interesting indeed, thank you. Did not knew that yet, but some time ago I created an whole house with CSG Brushes and it lead to heavy performance issues, because its creates a LOT of entites. My performance where ways better when using an optimised single model. But your tip also works with models I guess. However be careful to not create more entites than you need. I dont know how good I am in level design and yes its a fun part ineed, but have not gathered much experience yet. I am working on all of my systems, you know all that coding stuff. This is where most of the beginner gamedevs fail, thats why I decided to start with that. On 23.8.2017 at 3:19 PM, randomdude said: If you ever have a performance problem or no idea how to give your maps a special touch just let me know Will definitely come back to you On 23.8.2017 at 3:19 PM, randomdude said: I have not seen something from you Well working hard, I guess cant take too long till I will show some stuff. I have huge plans working for about an year on my current project, but not much model/animation work is done yet, but as mentioned before its just an framework no real game or something but whatsoever ^^ Edit: This could be interesting if it comes to raycasting, actually its the command to perfrom an raycast: https://www.leadwerks.com/learn?page=API-Reference_Object_Entity_Pick Quote Link to comment Share on other sites More sharing options...
randomdude Posted August 24, 2017 Author Share Posted August 24, 2017 Quote The idle animation needs 500 miliseconds to blend into the walking animation. So the blending always happens you just decide how long it takes, if it is nil or 0 then no blending happens. Ohh ok thats the infomation I needed, so it does it always, I dont need to call for it. Thank you very much. Quote I have that problem with good working animations and models, but I really want to learn it. Currently getting into ZBrush. My Animation skills are at least good enough to create some basic motions. Had the same issue with animations, takes long to understand all this variations and stuff. I made a character for that purpose which has a big load of MoCap-animations which can be loaded on other Characters with the same rig in LW. Quote Did not knew that yet, but some time ago I created an whole house with CSG Brushes and it lead to heavy performance issues, because its creates a LOT of entites. Yes if you do it not this way or lets say you are not making all unseen sides invisible you get fps problems. The engine is rendering any textured side. you can either retexture all unseensides on your house or you make it new with that technique. What is very importent as well, is that you make sure the CSG do not overlap into other CSG, this will drop your FPS as well. In LW itself you cant make specific sides of models invisible as far as I know. The point is you loose all of LW beauty if you use too much models. In my opinon Models are not more than details. But its more my personal preference. Quote Well working hard, I guess cant take too long till I will show some stuff. I have huge plans working for about an year on my current project, but not much model/animation work is done yet, but as mentioned before its just an framework no real game or something but whatsoever ^^ Haha no worries, just said that to reason my mapping drift, due to my bad English the thread says I´m helping someone so, we are back on track. haha Quote Link to comment Share on other sites More sharing options...
Phodex Games Posted August 25, 2017 Share Posted August 25, 2017 12 hours ago, randomdude said: I made a character for that purpose which has a big load of MoCap-animations MoCap? How did you do that? You dont have a professional mocap studio I guess. You used that kinect thing did'nt you? 12 hours ago, randomdude said: Yes if you do it not this way or lets say you are not making all unseen sides invisible you get fps problems Of course, but I am talking about you have an entity in the editor for every csg brush, so for larger structures you will generate many entites. A single modle just counts as one entity. And the number of entites also affects performance know what I mean? 12 hours ago, randomdude said: In LW itself you cant make specific sides of models invisible as far as I know. The point is you loose all of LW beauty if you use too much models. True, but thats what I meant, you can also hide faces inside a model editing software. Actually thats a fundamental thing to even DELETE sides which are not needed, or you cannot see. So you can actually do this even better within a model. But IF you want to work with csg brushes that thing you showed about faces is very important. I dont really know what you mean, that models make the game look worse, because you can create any model you want and its up to YOU how it looks like. You can actually create models looking like the csg brushes ^^, know what I mean. But I guess what you actually mean is to not overload your scene with details dont you? Quote Link to comment Share on other sites More sharing options...
randomdude Posted August 25, 2017 Author Share Posted August 25, 2017 Quote MoCap? How did you do that? You dont have a professional mocap studio I guess. You used that kinect thing did'nt you? Sure I make them in my basement. haha Nah google for free BVH, makehuman, makewalk and blender. In blenders makewalk-tab you need to select "global edit" and there "fixate bone location". then export as .fbx. The thing I dont know at the moment is how to reassign the positioning dot. Maybe you know? I make a video. I want this Dot in the center, but I cant grab it, or just the name of it would be good to know. https://www.twitch.tv/videos/169660004 (Edit: Nevermind I found it, you need a extra programm called "bvhacker" to get it in position. Thats the downside of free stuff. xD) Quote Of course, but I am talking about you have an entity in the editor for every csg brush, so for larger structures you will generate many entites. A single modle just counts as one entity. And the number of entites also affects performance know what I mean? Sure I understand. I´m not a complete expert on this, I just know for sure, that the faces will be rendered and calculated. So I keep them as low as possible. In the other ingame video I uploaded yesterday the fps drop to 30-60 at one point and that is because I made one NPC highpoly with over 40k polygones.I made my mainlocation with so many CSG, lights, particles and models and still have 60 fps an my pretty old graphic card. Its not entirly finished and I dont want to reveal it. Quote know what I mean. But I guess what you actually mean is to not overload your scene with details dont you? No, I get your point but I mean I´m not a modeler and I use Blender for such things. The models just look different and if you make for example an entire city with models in blender and add them into LW you have made you map in blender and thats what it looks like.You can do this but I personally dont like it. 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.