Jump to content

thehankinator

Members
  • Posts

    436
  • Joined

  • Last visited

Everything posted by thehankinator

  1. Is there a way that I can check to see if my games were uploaded with the old UGC system?
  2. I've not tried it yet but Microsoft released "Visual Studio Code", a free cross platform code editor. Looks pretty slick. https://code.visualstudio.com/
  3. Have you tried World::Pick() or any other Pick? I know you are asking in C++ but I think the FPSPlayer.lua script on collision will check the velocity of the player, if it's more N value it kills the player. You might be able to add the same sort of check in C++ or do the height check in lua.
  4. You could do something like this in the main loop of App.lua: In Start() self.paused = false In Loop() if self.window:KeyHit(Key.P) then self.paused = not self.paused if self.paused then Time:Pause() else Time:Resume() end end --Update the app timing Time:Update() --Update the world if self.paused then --draw your menu --if mouse clicked --if mouse is over button --do something else self.world:Update() end --Render the world self.world:Render() Basically read up on Time:Pause() and Time:Resume()
  5. yep 3 is a integer 3.0 is a double 3.0f is a float
  6. Ok I got it working, I had to download Blender, rotate the model then export it back to fbx, reimport into leadwerks. Looks like I am going to have to modify every single character from Arteria3d in blender, then screw around with the normals and resize them. What a pain. Certainly not what I thought I was buying. Anyway thanks for your help!
  7. It looks like you made a pivot and made it the parent of the monster? Did you then apply the script to the pivot?
  8. I am trying to use a monster I got from Arteria3d with the stock MonsterAI.lua. I've got all the same settings on the script as the crawler but the monster runs and attacks backwards. I've tried playing with the "Character angle" property in the physics tab but that appears to give very erratic behavior for any value other than 180. Setting 0 the monster move between the player location and the monster's initial position very very quickly until finally flying off the side of the world. Setting 90 and the monster spins really fast and flies off the side of my world. Finally setting 180, the monster moves and attacks properly but backwards. Any one have ideas? Thanks
  9. The buffer class appears to exist but not documented. I can see it's been suggested to add this documentation but was close to a year ago. Is there a reason why this was never documented? Like is it deprecated or unmaintained code? Is the API stable? I'd like to do something with multiple views or split screen or something but I wont bother if the API is going away or isn't stable. Suggestion: http://www.leadwerks.com/werkspace/topic/10171-buffer-commands-exposed-to-lua-with-documentation/
  10. Last night I had someone install the Leadwerks Game Launcher. It didn't go too smoothly as they happened to be missing visual c++ 2013 redistributables, I took a look inside the game launcher directory(C:\Program Files (x86)\Steam\SteamApps\common\Leadwerks Game Player\_CommonRedist) looks like they are not packaged with it. Leadwerks.dll is linked to 2013 and lua51.dll links to 2010 redistributables. Game Launcher should include those so that they get installed on first run of the Game Launcher.
  11. How would I do this in lua? I tried Maximized() but it remains false(makes sense). Is there some way to retrieve the style flags that a window was created with? Weird, It wont let me reply but I can edit my post. Anyway naturally after posting I remembered that it is getting set from System:GetProperty("fullscreen"). Derp. Please disregard.
  12. I was able to get this working. To test I used "cryogen_propb.mdl" from the scifi construction kit. The trick was that the editor would drop this model in as a Prop collision type. To fix this I went to the Scene tab, found the model (in my case it was called "cryogen_propb") expanded it to expose it's children. From there I found a child called "Form162"(yours will probably have a different name), when I selected it the whole model turned red in the editor viewports. It was this object that I changed the Collision type to Scene under the Physics tab. It seems like you have to specifically select the correct node and change this setting. I tried selecting the parent and all children and it wouldn't work.
  13. What's wrong with the Pick points? The p0 point is the monster's head, in the Crawler's case "self.entity:GetPosition()+Vec3(0,1.6,0)" pretty much nail's it. The p1 point (entity_pos) will be the exact position of the camera (ie the players head).
  14. Is it possible your wall is not set to "Scene" in the physics tab? Collision.LineOfSight only collides with Scene objects. The Pick() is checking for anything between the two points then only does the FOV check if there was nothing so the closest flag should not matter. The height of the monster shouldn't be changing (in this tutorial anyway) but it is casting the ray to the camera. When the player crouches, the camera's position changes. So there should be no need to do any additional checks.
  15. Great solution, my first ideas were far more complex.
  16. Item #3 http://www.leadwerks.com/werkspace/topic/12805-basic-sneaking-tutorial/
  17. *UPDATE* 6/22/15 I've added code for simple peeking functionality. This is a tutorial on how to implement a rudimentary sneaking mechanic to your game. The monster will only see the player if they in front of it, while taking into consideration of the height of the player. This means the player could crouch behind an object, not under one. I assume you are comfortable and familiar with lua script and Leadwerks 3.5, therefore I will not be covering lua syntax nor how to do basic things in Leadwerks. The code samples below will have the new code surrounded by comments, the rest is there just to give you reference to what section of the code we are working in. I broke this problem down into two sub tasks. Crouch to FPSPlayer Peek to FPSPlayer Field of view check to MonsterAI Initial setup Open your project. In the asset tab, navigate to the FPSPlayer.lua script. Make a copy of it, call it FPSPlayerSneak.lua. Next at the top of FPSPlayerSneak.lua, we need to add the variables that we will need. Script.mouseDifference = Vec2(0,0) Script.playerMovement = Vec3(0,0,0) Script.tempJumpForce = 0 --CROUCH BEGIN Script.crouched = false Script.crouchheight = 1.0 --CROUCH END --PEEK BEGIN Script.peek_translate = 0 Script.peek_distance = 0.5 --PEEK END function Script:CycleWeapon(direction) Script.crouched This flag indicates if the player is currently crouching. You could set this flag if you wanted the player to start crouched. Script.crouchheight This is the height of the player when crouching. You could adjust this if you wanted the player to be taller or shorter while crouched Script.peek_translate This variable keeps track of how far we are peeking, no need to play with this one Script.peek_distance Defines the distance the player can peek, increase it to lean further Add crouch Toward the bottom of the UpdatePhysics function we have two things that need to be done. First, check for the control key then toggle a flag indicating if the player should be crouched or not. --Give the player an extra boost when jumping playerMovement = playerMovement * 1.6 end --CROUCH BEGIN -- Check for crouching if window:KeyHit(Key.ControlKey) then self.crouched = not self.crouched end --CROUCH END --With smoothing --Position camera at correct height and playerPosition self.entity:SetInput(self.camRotation.y, playerMovement.z, playerMovement.x, jump , false, 1.0, 0.5, true) A few lines down, we need to position the camera to the required height based on the crouch flag newCameraPos = Vec3(playerPos.x, newCameraPos.y, playerPos.z) --CROUCH BEGIN local target_height --determine the height of the camera if self.crouched then target_height = self.crouchheight else target_height = self.eyeheight end --calculate the new camera position if newCameraPos.y<playerPos.y + target_height then newCameraPos.y = Math:Curve(playerPos.y + target_height, newCameraPos.y, self.camSmoothing) else newCameraPos.y = playerPos.y + target_height end --CROUCH END self.camera:SetPosition(newCameraPos) Add peek We will continue working in FPSPlayerSneak.lua First we need to remap the E key from use to something else, for the sake of this tutorial I am going to use G. Scroll down the UpdateWorld() function and free up that E key. --PEEK BEGIN if window:KeyHit(Key.G) then --PEEK END if self.carryingEntity then self:DropEntityCarrying() Now that both the Q and E keys are available to use, we need to check them then set the direction we are going to shift the camera. -- Check for crouching if window:KeyHit(Key.ControlKey) then self.crouched = not self.crouched end --CROUCH END --PEEK BEGIN if window:KeyDown(Key.Q) then self.peek_translate = Math:Curve(-self.peek_distance, self.peek_translate, self.camSmoothing) elseif window:KeyDown(Key.E) then self.peek_translate = Math:Curve(self.peek_distance, self.peek_translate, self.camSmoothing) else self.peek_translate = 0 end --PEEK END --With smoothing Finally at the bottom of this function we are going to translate the camera to the side in the direction we are peeking self.camera:SetPosition(newCameraPos) --PEEK BEGIN self.camera:SetPosition(Transform:Point(self.peek_translate,0,0,self.camera,nil)) --PEEK END end Field of view check to MonsterAI In the asset tab, navigate to the MonsterAI.lua script. Make a copy of it, call it MonsterAIFOV.lua. Open that up and find the ChooseTarget() function. local d = self.entity:GetDistance(entity) local pickinfo=PickInfo() --LOS BEGIN local entity_pos if entity.script.camera ~= nil then--if there is a camera object entity_pos = entity.script.camera:GetPosition(true)--use the camera position else entity_pos = entity:GetPosition(true)--otherwise, use the entity's position end --cast a ray from the monster's eye to the target position if self.entity.world:Pick(self.entity:GetPosition()+Vec3(0,1.6,0),entity_pos,pickinfo,0,false,Collision.LineOfSight)==false then --when we reach here, the target is in line of sight --now we need to check if the target is in the monster's field of view. --we are going to measure the angle from the direction the monster is looking --to the target. local dir_facing = Transform:Normal(0,0,1,self.entity,nil):Normalize() local dir_to_target = (entity:GetPosition() - self.entity:GetPosition()):Normalize() local angle = math.acos(dir_facing:Dot(dir_to_target)) local window=Window:GetCurrent() --compare the resulting angle in radians, this determines the monster's field of view --or if the player is running(thanks nick.ace!) if angle > 2.0943951 or window:KeyDown(Key.Shift) then --~120 or degees return entity.script end end --LOS END end The math in this section is kind of confusing. I got adapted the formulas from the following website. http://blog.wolfire.com/2009/07/linear-algebra-for-game-developers-part-2/ Wrap up Set your monster to use MonsterAIFOV.lua, this should give you the FOV check. Then, set your player object to use FPSPlayerCrouch.lua, this will allow you to crouch when you press the control key. Feedback welcome.
  18. This is slightly misleading after going to Arteria3D's site: Still seems like a good deal though!
  19. This is an annoying problem. When I get a LE update I cringe because it is awkward to go through the log and find all the .bak files to do a diff on the current script then merge the two scripts. I made sure to specify what version of LE I used when developing the tutorial. I've taken to making a copy of every script I modify (as I did in the this tutorial), updates be damned. I like the idea of an improved FPSPlayer script(regardless of design pattern) but until it replaces the default LE scripts I think it is best to base a tutorial on the scripts that are known, working and available with the default installation.
  20. The purpose of this post was intended to show a basic concept. Most of the logic to achieve this battery would look pretty similar if it was developed utilizing a different design pattern. I expect that most people would take the concept and implement it in their scripts the way they see fit. This is part of the reason I didn't post the whole script, just the parts that matter. Besides, it's a moving target to satisfy everyone's code structure. Do you have have a prototype of your ideal FPSPlayer script?
  21. That works for this pickup but I would refrain from making that sort of change to the FPSPlayer script. It could break some other item's Use function because they would be expecting the script object rather than an entity object. I would change FPSPlayer script back to if usableentity~=nil then --Use the object, whatever it may be usableentity.script:Use(self) Then change the pickup script to Script.battery_power = 50 --int "Battery power" function Script:Use(person) if person.battery_level ~= nil and person.battery_max_level ~=nil then if person.battery_level < person.battery_max_level then person.battery_level = person.battery_level + self.battery_power if person.battery_level > person.battery_max_level then person.battery_level = person.battery_max_level end self.entity:Release() end end end
  22. I had some time tonight. Not sure which task I'll look into next. Item #1 http://www.leadwerks.com/werkspace/topic/12783-flashlight-battery-tutorial/
  23. This is a short tutorial to add a battery to the default FPSPlayer.lua script. I am going to assume you are familiar with lua script and Leadwerks 3.5 so I wont be spending much time explaining how to place entities on a map etc. The code samples below will have the new code surrounded by comments, the rest is there just to give you reference to what section of the code we are working in. I broke this problem down into 3 separate aspects. Flashlight logic Battery level indication (HUD) Battery pickup Initial Setup Open your project or create a new one. In the asset tab, navigate to the FPSPlayer.lua script. Make a copy of it, call it FPSPlayerBattery.lua. Next at the top of FPSPlayerBattery.lua, we need to add the variables that we will need to make this happen. Script.mouseDifference = Vec2(0,0) Script.playerMovement = Vec3(0,0,0) Script.tempJumpForce = 0 --+++BATTERY VARIABLES BEGIN+++ Script.battery_level = 100 --float "Battery level" Script.battery_max_level = 100 --float "Battery max level" Script.battery_discharge_rate = 0.5 --float "Battery discharge rate" --+++BATTERY VARIABLES END+++ function Script:CycleWeapon(direction) local n,weapon local foundindex=false Script.battery_level The current level. In this example I made 100 the current. If you wanted the player to start with no battery power, you could change this to 0. Script.battery_max_level The max level of the battery. If the player doesn't have a battery, you could set this to 0 or if they got an upgraded battery bump this value up. Script.battery_discharge_rate The speed which the battery will die while the light is on. Flashlight logic This will occur in the UpdatePhysics function of FPSPlayerBattery.lua. --Update the footstep sounds when walking self:UpdateFootsteps() --+++BATTERY LOGIC BEGIN+++ --Toggle the flash light on and off if window:KeyHit(Key.F) then if self.flashlight:Hidden() then --check if the flashlight is off if self.battery_level > 0 then --check if we battery power self.sound.flashlight:Play() --play the sound self.flashlight:Show() -- turn on the light end else --light is already on self.sound.flashlight:Play() --play the sound self.flashlight:Hide() --turn off the light end end if not self.flashlight:Hidden() then --check if the light is on self.battery_level = self.battery_level - self.battery_discharge_rate * Time:GetSpeed() --light is on, reduce the battery level. if self.battery_level <= 0 then --check if the battery died self.battery_level = 0 --just incase the battery level went below 0, reset it to 0 self.sound.flashlight:Play() --play the usual sound self.flashlight:Hide() --turn off the light end end --+++BATTERY LOGIC END+++ --Apply forces to make the carried object move the way we want if self.carryingEntity then Battery level indication (HUD) This will be a bar that will have a green color if you have power, red if you get low. We need to look in the PostRender function of FPSPlayerBattery.lua. context:SetBlendMode(1) context:SetColor(0,0,0,0.5) local indent=8 local w = 180 local h = 40 --+++BATTERY INDICATOR BEGIN+++ local battery_percent = self.battery_level / self.battery_max_level --calculate the percentage of battery power remaining context:SetColor( 1 - battery_percent, battery_percent, 0, 1) --as the battery dies the red component increases while the green decreases context:DrawRect( 50, 50, 100 * battery_percent, 20) --rectangle width is dependent on the percentage of battery remaining. Wider with more power. --+++BATTERY INDICATOR END+++ end Battery pickup In the assets tab, navigate to Scripts/Objects/Items. Create a new script called PickupBattery.lua. Open that sucker up and delete the contents. Script.battery_power = 50 --int "Battery power" function Script:Collision(entity, position, normal, speed) local p = entity.script --for convenience if p.battery_level ~= nil and p.battery_max_level ~= nil then --make sure what collided has the required battery variables if p.battery_level < p.battery_max_level then --make sure that the battery isn't already full p.battery_level = p.battery_level + self.battery_power --add the power to the battery if p.battery_level > p.battery_max_level then --check to see if we over filled the battery p.battery_level = p.battery_max_level --set the battery to max value end self.entity:Release() --get rid of the pickup now that the power was added end end end Script.battery_power How much power this pickup will give the player Wrap up That is all the parts needed. Set your player entity to use FPSPlayerBattery.lua. Set the script on the pickups in your level to PickupBattery.lua. I've not decided if I will upload the completed scripts, I don't want spoil the fun of doing it yourself . Feedback welcome.
×
×
  • Create New...