Megalocerous Posted June 23, 2020 Share Posted June 23, 2020 First off - hello! It has been a while since I've used Leadwerks, but I have decided to install it again and actively use it. I figured the best way to remember how to use the engine would be to re-create my Beach Roll entry submitted for one of the summer jams a few years back, but make it less bad and add a lot of fun level design obstacles/features, updated camera view, actual game menu etc. So for most of this I have been creating scripts in lua and making them usable in flowgraph. This way I can just script what the object should do, then I can just wire it up in the level as its needed. The current issue I have is with creating a "Wind Zone" trigger script. Basically when the player rolls into the trigger, it should add force in a given direction based on the scripts force vector property. Then when the player leaves the trigger it should stop applying the force. I used the collision-enter-exit script from the wikidot to achieve this. The only problem is that when I move into the first zone, it applies the correct force, the second zone works properly, the third zone does...but then if I move back into any of the previous zones it will still apply the last zones force. Upon re-entering the same zone (after it applied the incorrect force the first time) it applies the right force. I'm sure it is either a logic issue or the way I am handling the variable for it, but I've attached a test project with a map and everything wired up in case anyone wanted to take a look. Thanks! WindZoneTest.zip Quote Link to comment Share on other sites More sharing options...
Josh Posted June 23, 2020 Share Posted June 23, 2020 I was curious and took a look at the flowgraph. That is some pretty complex logic at first glance. If I was designing this I would probably just do something like this in the windzone script: function Script:Collision(entity, position, normal, speed) entity:AddForce(self.force) end Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Megalocerous Posted June 23, 2020 Author Share Posted June 23, 2020 Yeah I apologize I was working on it late last night and its possible that I over complicated it. That is similar to how the bounce block or bounce zone works, which is good on the initial collision. But for this I am thinking design wise that it will be a constant force added while you are inside the zone, but removing the force when you are outside of it. Just adding the force on collision like this doesn't check on exit and keeps applying it no? At least that is what seems to happen when I write it like that. Quote Link to comment Share on other sites More sharing options...
Megalocerous Posted June 25, 2020 Author Share Posted June 25, 2020 On 6/23/2020 at 4:40 PM, JMK said: I was curious and took a look at the flowgraph. That is some pretty complex logic at first glance. If I was designing this I would probably just do something like this in the windzone script: function Script:Collision(entity, position, normal, speed) entity:AddForce(self.force) end Just to follow up on this - This seems to work better in 4.5 then in 4.6. 4.6 seems to keep calling entity:AddForce() even after exiting the trigger zone, which I am guessing is not supposed to happen? Quote Link to comment Share on other sites More sharing options...
Megalocerous Posted June 25, 2020 Author Share Posted June 25, 2020 I think I fixed this by re-writing my player script differently and then using 2 different triggers. One that triggers the wind, one that disables it. Now when the player enters the "wind zone" they will be fighting against the force constantly and if they get pushed out of the zone they will stop having the force applied. Script.playerSpeed = 10.0 --float "Player Speed" Script.windForce = 20.0 --float "Wind Force" Script.windVector = Vec3(0,0,-1) --vec3 "Wind Vector" local isWindActivated = false function Script:Start() self.world = World:GetCurrent() self.isAlive = true -- Create camera self.camera = Camera:Create() -- self.camera:SetFOV(90) self.camera:SetProjectionMode(Camera.Orthographic) self.camera:SetZoom(50) --load the font self.font = Font:Load("Fonts/Ranchers-Regular.ttf",48) --update the camera self:UpdateCamera() end function Script:UpdateWorld() self:UpdateCamera() end function Script:UpdatePhysics() self:MovementInput() end function Script:UpdateCamera() self.camera:SetRotation(45, -35, 0) self.camera:SetPosition(self.entity:GetPosition().x, self.entity:GetPosition().y, self.entity:GetPosition().z) self.camera:Move(0, 0, -30) end function Script:MovementInput() local moveVector = Vec3() local window = Window:GetCurrent() if window:KeyDown(Key.W) then moveVector.z = 1 end if window:KeyDown(Key.S) then moveVector.z = -1 end if window:KeyDown(Key.A) then moveVector.x = -1 end if window:KeyDown(Key.D) then moveVector.x = 1 end local normalizedVector = moveVector:Normalize() * self.playerSpeed local vectorWithWind = (moveVector:Normalize() * self.playerSpeed) + (self.windVector * self.windForce) if isWindActivated then self.entity:AddForce(vectorWithWind) else self.entity:AddForce(normalizedVector) end end function Script:EnableWind()--in isWindActivated = true end function Script:Disable()--in isWindActivated = false end 1 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.