Jump to content

AggrorJorn

Members
  • Posts

    4,816
  • Joined

  • Last visited

Everything posted by AggrorJorn

  1. Here is a playlist to learn Lua and some lua specific functionality with Leadwerks.
  2. Have you searched in the workshop? First result for explosion: https://steamcommunity.com/sharedfiles/filedetails/?id=932421043&searchtext=explosion
  3. screenshot of scene and the settings perhaps? Restarting the editor? new test scene to try it out?
  4. IMaybe the enemy is close enough to the player, it stops moving and goes to the fighting animation. Perhaps there is no fight animation and moving is not enabled again.
  5. What do you mean with pack? Do you mean 'placed it in the level' or did you make a prefab? Can you post a working project (excluding assets that are not needed to reduce file size)? I will have a look this evening.
  6. I can get the editor/game crashing, but BSOD's? Can you check the windows event log and post any possible related errors here?
  7. Often starting in debug mode, can give you at least an error instead of just a crash. Starting adding nil checks and print out a console warning when something is nill when it shouldn't be
  8. Works fine for me. 1000 is a very high range value. I tested it with 50 1 character controller with default fps script 1 pivot with your soundsource script
  9. The source is now fixed at position vec3(0,0,1) which might not be the actual position of your helicopter. Can you upload the sound? I will try out on my pc and send you the results. source:SetPosition(sel.entity:GetPosition(true)) --Retrieve the position of the helicopter Note that if your helicopter is moving, you need to update the position of the source.
  10. I am assuming this means 'I use the default FPS player script that comes with Leadwerks'. This script creates a listenere. So if you have antther script in your scene that also creates a listener (either by attaching the script to an object or by using main.lua) than these 2 listeners are conflicting. Try creating your sound, without creating an additional listener and move your character close to the position of the source.
  11. Are you using the default character controller like @Thirsty Panther mentioned? If you do, the character controller script already creates a listener for you. Which is then probably conflicting with the listener you made. Can you share the entire script you are using right now?
  12. If you try out the example from the documentation and swap the audio with your helicopter sound, does it work? https://www.leadwerks.com/learn?page=API-Reference_Object_Source_SetRange range = 1.5 --Create a window window = Window:Create() context = Context:Create(window) --Load a sound local sound = Sound:Load("Sound/heli2.wav") --Create a source source = Source:Create() source:SetSound(sound) sound:Release() source:SetLoopMode(true) source:Play() source:SetPosition(Vec3(0,0,1)) --Create a listener local listener = Listener:Create() listener:SetPosition(0,0,0) while true do --Press up/down keys to adjust the source range if (window:KeyDown(Key.Up))then range = range + Time:GetSpeed()*0.1 end if (window:KeyDown(Key.Down))then range =range - Time:GetSpeed()*0.1 end if (range < 0)then range=0 end source:SetRange(range) if window:Closed() or window:KeyHit(Key.Escape) then return false end Time:Update() context:SetColor(0,0,0) context:Clear() context:SetColor(1,1,1) context:SetBlendMode(Blend.Alpha) context:DrawText("Range: "..range,2,2) context:Sync() end
  13. @Thirsty Panther Is right, leadwerks can do this for you. Sound file needs to be mono formatted though.
  14. fyi: recording (a part) of your screen can be done with the free OBS project: https://obsproject.com/.
  15. Yes, very well done. This already reads better than the very first script. So how does this script perform at the moment? Is it the intended behavior? What is the behavior you would want/expect? Do you have a video to display what is going on in your game right now?
  16. When a function has parameters (like the 'isNegative' example), then these do have any values automatically. They only get a value assigned to them when you call the function, and pass in existing values. Regardless if the calculations are correct and regardless whether this can all be done in a few lines with the right calculation, right now I am more concerned about how your code is structured. By organizing your code, we can find the solution faster. So lets try and break the code down from your very first post and imrove it step by step. Looking at the if statements Your code is currently divided in 5 if statements that check the playerY rotation. Your first if statement covers the forward direction: -30 and 30. That looks good. Your 2nd and 3rd if statement are for the backwards direction. These can be combined to 1 if statement. Saves you 15 lines of code. elseif (playerYRotation >= 150 and playerYRotation <= 180) or (playerYRotation >= -180 and playerYRotation <= -150) then DrawRect() Every single DrawRect you use inside the if statement does the same thing. This can be reduced to a single DrawRect() and using a single drawCoordinates variables that gets filled by 1 of the if statements. This saves you about 18 lines of code. Current status of the script We are not there yet, but here is how that code looks in the meantime: 36 lines shorter. Let me know if you have questions about what I have done so far. Once that is clear we will continue improving: Script.target = nil -- entity "Target" Script.dotSize = 5 -- int "Dot Size" function Script:Start() self.player = self.entity:GetParent() self.mapPos = Vec2(200, 200) end function Script:PostRender(context) local x = self.mapPos.x / 2 local y = self.mapPos.y / 2 local playerPos = self.player:GetPosition(true) local enemyPos = self.target:GetPosition(true) local playerYRotation = self.player:GetRotation(true).y local drawCoords = Vec2(0,0) --We will use this variable to store the calculated draw position context:SetBlendMode(1) context:SetColor(1, 1, 1, 1) context:DrawRect(x, y, self.dotSize, self.dotSize) context:SetColor(1, 0, 0, 1) if playerYRotation <= 30 and playerYRotation >= -30 then -- facing forward if playerPos.x < enemyPos.x and playerPos.z < enemyPos.z then -- lower left drawCoords.x = x + (-Math:Cos(playerYRotation) * (playerPos.x - enemyPos.x) - Math:Sin(playerYRotation) * (enemyPos.x - playerPos.x)) drawCoords.y = y + (-Math:Sin(playerYRotation) * (enemyPos.z - playerPos.z) + Math:Cos(playerYRotation) * (playerPos.z - enemyPos.z)) elseif playerPos.x > enemyPos.x and playerPos.z < enemyPos.z then -- lower right drawCoords.x = x + (-Math:Cos(-playerYRotation) * (playerPos.x - enemyPos.x) - Math:Sin(-playerYRotation) * (enemyPos.x - playerPos.x)) drawCoords.y = y + (Math:Sin(playerYRotation) * (enemyPos.z - playerPos.z) + Math:Cos(playerYRotation) * (playerPos.z - enemyPos.z)) elseif playerPos.x < enemyPos.x and playerPos.z > enemyPos.z then -- upper left drawCoords.x = x + (-Math:Cos(-playerYRotation) * (playerPos.x - enemyPos.x) - Math:Sin(-playerYRotation) * (enemyPos.x - playerPos.x)) drawCoords.y = y + (Math:Sin(playerYRotation) * (enemyPos.z - playerPos.z) + Math:Cos(playerYRotation) * (playerPos.z - enemyPos.z)) elseif playerPos.x > enemyPos.x and playerPos.z > enemyPos.z then -- upper right drawCoords.x = x + (-Math:Cos(playerYRotation) * (playerPos.x - enemyPos.x) - Math:Sin(playerYRotation) * (enemyPos.x - playerPos.x)) drawCoords.y = y + (-Math:Sin(playerYRotation) * (enemyPos.z - playerPos.z) + Math:Cos(playerYRotation) * (playerPos.z - enemyPos.z)) end elseif (playerYRotation >= 150 and playerYRotation <= 180) or (playerYRotation <= -150 and playerYRotation >= -180 ) then -- facing backward if playerPos.x < enemyPos.x and playerPos.z < enemyPos.z then -- lower left drawCoords.x = x + (-Math:Cos(playerYRotation) * (playerPos.x - enemyPos.x) - Math:Sin(playerYRotation) * (enemyPos.x - playerPos.x)) drawCoords.y = y + (-Math:Sin(playerYRotation) * (enemyPos.z - playerPos.z) + Math:Cos(playerYRotation) * (playerPos.z - enemyPos.z)) elseif playerPos.x > enemyPos.x and playerPos.z < enemyPos.z then -- lower right drawCoords.x = x + (-Math:Cos(-playerYRotation) * (playerPos.x - enemyPos.x) - Math:Sin(-playerYRotation) * (enemyPos.x - playerPos.x)) drawCoords.y = y + (Math:Sin(playerYRotation) * (enemyPos.z - playerPos.z) + Math:Cos(playerYRotation) * (playerPos.z - enemyPos.z)) elseif playerPos.x < enemyPos.x and playerPos.z > enemyPos.z then -- upper left drawCoords.x = x + (-Math:Cos(-playerYRotation) * (playerPos.x - enemyPos.x) - Math:Sin(-playerYRotation) * (enemyPos.x - playerPos.x)) drawCoords.y = y + (Math:Sin(playerYRotation) * (enemyPos.z - playerPos.z) + Math:Cos(playerYRotation) * (playerPos.z - enemyPos.z)) elseif playerPos.x > enemyPos.x and playerPos.z > enemyPos.z then -- upper right drawCoords.x = x + (-Math:Cos(playerYRotation) * (playerPos.x - enemyPos.x) - Math:Sin(playerYRotation) * (enemyPos.x - playerPos.x)) drawCoords.y = y + (-Math:Sin(playerYRotation) * (enemyPos.z - playerPos.z) + Math:Cos(playerYRotation) * (playerPos.z - enemyPos.z)) end elseif playerYRotation >= 30 and playerYRotation <= 149 then -- facing right if playerPos.x < enemyPos.x and playerPos.z < enemyPos.z then -- lower left drawCoords.y = x + (Math:Cos(playerYRotation) * (playerPos.x - enemyPos.x) - Math:Sin(playerYRotation) * (enemyPos.x - playerPos.x)) drawCoords.x = y + (-Math:Sin(playerYRotation) * (enemyPos.z - playerPos.z) - Math:Cos(playerYRotation) * (playerPos.z - enemyPos.z)) elseif playerPos.x > enemyPos.x and playerPos.z < enemyPos.z then -- lower right drawCoords.y = x + (-Math:Cos(playerYRotation) * (playerPos.x - enemyPos.x) - Math:Sin(playerYRotation) * (enemyPos.x - playerPos.x)) drawCoords.x = y + (-Math:Sin(playerYRotation) * (enemyPos.z - playerPos.z) - Math:Cos(playerYRotation) * (enemyPos.z - playerPos.z)) elseif playerPos.x < enemyPos.x and playerPos.z > enemyPos.z then -- upper left drawCoords.y = x + (-Math:Cos(playerYRotation) * (playerPos.x - enemyPos.x) - Math:Sin(playerYRotation) * (enemyPos.x - playerPos.x)) drawCoords.x = y + (-Math:Sin(playerYRotation) * (enemyPos.z - playerPos.z) - Math:Cos(playerYRotation) * (enemyPos.z - playerPos.z)) elseif playerPos.x > enemyPos.x and playerPos.z > enemyPos.z then -- upper right drawCoords.y = x + (Math:Cos(playerYRotation) * (playerPos.x - enemyPos.x) - Math:Sin(playerYRotation) * (enemyPos.x - playerPos.x)) drawCoords.x = y + (-Math:Sin(playerYRotation) * (enemyPos.z - playerPos.z) - Math:Cos(playerYRotation) * (playerPos.z - enemyPos.z)) end elseif playerYRotation <= -30 and playerYRotation >= -149 then -- facing left if playerPos.x < enemyPos.x and playerPos.z < enemyPos.z then -- lower left drawCoords.y = x + (Math:Cos(playerYRotation) * (playerPos.x - enemyPos.x) - Math:Sin(playerYRotation) * (enemyPos.x - playerPos.x)) drawCoords.x = y + (-Math:Sin(playerYRotation) * (enemyPos.z - playerPos.z) - Math:Cos(playerYRotation) * (playerPos.z - enemyPos.z)) elseif playerPos.x > enemyPos.x and playerPos.z < enemyPos.z then -- lower right drawCoords.y = x + (-Math:Cos(playerYRotation) * (playerPos.x - enemyPos.x) - Math:Sin(playerYRotation) * (enemyPos.x - playerPos.x)) drawCoords.x = y + (-Math:Sin(playerYRotation) * (enemyPos.z - playerPos.z) - Math:Cos(playerYRotation) * (enemyPos.z - playerPos.z)) elseif playerPos.x < enemyPos.x and playerPos.z > enemyPos.z then -- upper left drawCoords.y = x + (-Math:Cos(playerYRotation) * (playerPos.x - enemyPos.x) - Math:Sin(playerYRotation) * (enemyPos.x - playerPos.x)) drawCoords.x = y + (-Math:Sin(playerYRotation) * (enemyPos.z - playerPos.z) - Math:Cos(playerYRotation) * (enemyPos.z - playerPos.z)) elseif playerPos.x > enemyPos.x and playerPos.z > enemyPos.z then -- upper right drawCoords.y = x + (Math:Cos(playerYRotation) * (playerPos.x - enemyPos.x) - Math:Sin(playerYRotation) * (enemyPos.x - playerPos.x)) drawCoords.x = y + (-Math:Sin(playerYRotation) * (enemyPos.z - playerPos.z) - Math:Cos(playerYRotation) * (playerPos.z - enemyPos.z)) end end context:DrawRect(drawCoords.x, drawCoords.y, self.dotSize, self.dotSize) context:SetBlendMode(0) context:SetColor(1, 1, 1, 1) context:DrawText( Math:Round(playerPos.x) .. "," .. Math:Round(playerPos.z) .. "/" .. Math:Round(enemyPos.x) .. "," .. Math:Round(enemyPos.z), 20, 20 ) context:DrawText(playerYRotation, 20, 50) context:SetBlendMode(1) end
  17. Thanks for the replies @Thirsty Panther and @gamecreator. I am afraid the models that I bought do not have this element LayerElementColor but instead are refering to a material. There are no textures in the model pack, so I guess some other tricks are applied in other engines. Anyway, I am sure I can find some fbx batch export with color vertex somewhere for blender. Thanks for the help. If I find something useful, I will post back here.
  18. Okay lets first practice by making a very basic function. Lets make basic functions that returns the calculation that happens several times in your code: Take for instance this line: local Y = y+(-Math:Sin(a)*(enemy.z-pos.z) + Math:Cos(a)*(pos.z-enemy.z)) This line already exists 6 times in your code. So if you have an error in this calculation, you have change it 6 times. This makes your code hard to read and mistakes are easily made. So lets try to turn that in to a basic function: function GetYDrawCoordinate1(y, enemy, pos) return = y+(-Math:Sin(a)*(enemy.z-pos.z) + Math:Cos(a)*(pos.z-enemy.z)) end This function now has 3 parameters that need to be filled in when you call it. I would also advice to rename the y and pos variable to something clearer. Something that tells you what exactly is stored in the variable. local Y = GetYDrawCoordinateTest1(y, enemy, pos) A generic video on how functions with parameters work: Let me know how that goes and we move on to the rest of the code.
  19. Regardless of whether the code is right, I think your script can become a clearer/easier to read if you make use of functions. Every single if statement does more or less the same thing with only slight deviation. --current first if statement local X = x+(-Math:Cos(-a)*(pos.x-enemy.x) - Math:Sin(-a)*(enemy.x-pos.x)) local Y = y+(Math:Sin(a)*(enemy.z-pos.z) + Math:Cos(a)*(pos.z-enemy.z)) context:DrawRect(X,Y,s,s) --Format to: if statement local drawCoord = GetDrawCoordinate(Vec2(X, Y), playerPos, enemyPos, true, yRotation) context:DrawRect(drawCoord.x, drawCoord.y, s, s) end --Helper function that retrieves the right DrawCoords function GetDrawCoordinate(mapPos, playerPos, enemyPos, isNegative, yRotation) local dir = 1; if isNegative then dir = -1 end local x = mapPos.x+(dir * Math:Cos(dir * yRotation)*(playerPos.x-enemy.x) - Math:Sin(dir * yRotation)*(enemyPos.x-playerPos.x)) local y = mapPos.y+(-Math:Sin(yRotation)*(enemyPos.z-playerPos.z) + Math:Cos(yRotation)*(playerPos.z-enemyPos.z)) return Vec2(x,y) end
  20. With the new engine in development, the forum itself has become rather quiet. You will find most activity in the projects section as well as the official discord server.
  21. Should vertex colored fbx models work out of the box? I have a collection (+100) models that are vertex colored instead of having any textures. Loading them in using the editor, they remain grey. I tried to see if would require some sort of default empty material but to no avail. Opening them in other engines works directly. Does anyone have experience with this? This topic mentions altering some info in blender, but I am looking to see I can achieve this without actually altering all 100+ models in an external modeling program.
  22. There is no build in way to force the pivot3 scripts from being exucted first. What you can do is wait a couple of frames before calling the for loop in your pivot 3 script.
  23. Please, for future posts, attach your entire script in the question (and in code format). The community wants to help you and the more information you provide, the faster you are going to get a solution.
  24. Without seeing the actual script you have right now, we can only guess as to why it doesn't work. The script:hurt() function looks a little of. I think you want to use: if window:KeyHit(Key.U) then self:hurt (100) end See this tutorial on functions https://www.youtube.com/watch?v=x9Wi8Rh7M58
×
×
  • Create New...