WazMeister Posted July 14, 2023 Share Posted July 14, 2023 Hi, I'm struggling to get movement when both forward key and right or left key (strafe) is pressed at same time, one either overrides the forward and do not work together to move forwards while strafing. Be n ice to have model or a animation play as if its moving at the angle too. How do I get such results if my code for movement is the following system? Many Thanks --Set key button varibles local move = 0 local strafe = 0 local keyHit_forward = false local keyHit_backward = false local keyHit_left = false local keyHit_right = false --Player Movement if window:KeyDown(Key.W) then keyHit_forward = true end if window:KeyDown(Key.S) then keyHit_backward = true end if window:KeyDown(Key.A) then keyHit_left = true end if window:KeyDown(Key.D) then keyHit_right = true end --Reset player to IDLE STATE if move == 0 or strafe == 0 then player.state = 1 end --Key Actions ::rescanactions:: if keyHit_forward then move = -self.walkSpeed player.state = 2 end if keyHit_backward then move = self.walkSpeed - 0.5 player.state = 3 end if keyHit_left then strafe = self.walkSpeed + 2 player.state = 4 end if keyHit_right then strafe = - (self.walkSpeed + 2) player.state = 5 end Quote 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 More sharing options...
Yue Posted July 15, 2023 Share Posted July 15, 2023 I hope this gives you an idea. CMove={ -- Constructor. Create = function(self,player,camera) local this={} setmetatable(this,self) self.__index = self function this:Init() self.camera = camera self.player = player self.vel = 0 self.angle = 0 end function this:Update(startEngine) self.vel = 0 if startEngine == false then self.player:SetPhysicsMode(Entity.CharacterPhysics) self.player:SetCollisionType(Collision.Character) self.player:SetMass(200) if win:GetKeyDown(Key.Shift) == false then if win:GetKeyDown(Key.W) then self.vel = -1.2 self.angle = self.camera:GetRotation(true).y - 180 elseif win:GetKeyDown(Key.S) then self.vel = -1.2 self.angle = self.camera:GetRotation(true).y end else if win:GetKeyDown(Key.W) then self.vel = -3.0 self.angle = self.camera:GetRotation(true).y - 180 elseif win:GetKeyDown(Key.S) then self.vel = -3.0 self.angle = self.camera:GetRotation(true).y end end self.rotCamera = self.camera:GetRotation(true).y self.player:SetInput(self.angle, self.vel, 0, 0,false) else self.player:SetPhysicsMode(Entity.RigidBodyPhysics) self.player:SetMass(0) self.player:SetCollisionType(Collision.None) self.player:StopAnimation() end end this:Init() return(this) end } Quote Link to comment Share on other sites More sharing options...
WazMeister Posted July 15, 2023 Author Share Posted July 15, 2023 How odd, the command win:GetKeyDown... I used that and get errors, it does not reference win or GetKeyDown in the documentation either.. Where does that come from? Quote 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 More sharing options...
WazMeister Posted July 15, 2023 Author Share Posted July 15, 2023 I done a quick stream, as I struggle to put in words what I'm trying to do. Hopefully makes sense? Quote 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 More sharing options...
Yue Posted July 15, 2023 Share Posted July 15, 2023 5 hours ago, WazMeister said: How odd, the command win:GetKeyDown... I used that and get errors, it does not reference win or GetKeyDown in the documentation either.. Where does that come from? It is my coding, lua script is not oriented to the object programming paradigm (Poo), however it can be used without any problem to organize the code. Ç In other words win is a custom object, and instead of using KeyDown, the identifier encapsulates this with a GetKeyDown. But internally it is KeyHit, the most readable would be to call it Input. 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.