Jump to content

Top Down View (Shooter) - Done Right?


WazMeister
 Share

Recommended Posts

Hi all,

 

Sorry, back again!  So while learning LeadWerks engine I finally got a Top Down View working with animations.  It's a little buggy,  the idle animation was working fine but now stutters and Sprint has a slight frame jump or something.

I'm just wondering if someone would have the time to view my progress and code to check I am on the right track or if it should be done diffrently?  Not much help content for Leadwerks anymore so forums are my saving grace (hopefully).

I wanted to add an animation of turning / stepping when on the spot and holding A or D (turning) but it did not no work, animation just went about 10000 miles per hour and just odd?!?

Short video below, may want to skip to around 45 seconds to see progress and then pause on code at end.

 

Many Thanks!

 

  • Like 1

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

Also struggling to make it so when space is held down while o the spot,  the run animation still triggers.  Tried adding another check below, but get error of a "Then" should be added after the >?

Think I've got it wrong somewhere obviously!

 

if window:KeyDown(Key.Space) and self.entity:X(>0) then
		self.walkspeed = self.runspeed
		self.entity:PlayAnimation("Run", .08, 200)
	else
		self.entity:PlayAnimation("Idle", 0.7, 500)
		self.walkspeed = .02
	end
	--Update the camera each frame
	self:UpdateCamera()

 

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

19 minutes ago, Josh said:
if window:KeyDown(Key.Space) and self.entity.position.x > 0 then

Thank you Josh!

Did not realise there was a command like that, can only find Setposition and Getposition in document.

Good to know the above, but did not fix my problem.  I'm assuming it's because it's not using a typical spd = 3,  player.x = spd and then we can check if x is greater than 0 .. i.e his moving.

It's using the Move function, so do I need to check for something else?  The above, only work if the player is on the grid greater than 0... and holding button down while standing on spot still plays animation..  if I move back to far left.... the sprint does not work at all etc.

If I may, another query.  I'm not undertanding what the documentation means when it shows multiple syntax for a command.

Example MOVE details the below,  2x options for syntax.. I just went with the 2nd one as it makes more basic sense to me.  how would the Vec3 Position version work would the x, y ,z go in as argument without commas and wraps it up or something?

Syntax

  • void Move(Vec3 position, bool global=false)
  • void Move(number x, number y, number z, bool global=false)

Parameters

  • position: the movement to add.
  • x: the X component of the movement to add.
  • y: the Y component of the movement to add.
  • z: the Z component of the movement to add.
  • global: if set to true, the scale of the movement will be in global space, otherwise it will be affected by the entity's own scale.

 

 

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

You can do either of these:

entity:SetPosition(x, y, z)
entity:SetPosition(Vec3(x, y, z))

It mostly just depends on what the variables you want to use are. Both variations are included for convenience. If you already had a Vec3, it would be easier to use the command that accepts a Vec3, otherwise the individual parameters are probably easier.

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

Thanks again Josh, I was just about to joke Leadwerks should hire you! You always seem to be the one that respones and has great knowledge. Then realised they already did with Staff under your profile! ;)

 

Do you know what I must change in my code to make the sprint animation only work while player is moving, rather than it playing the animation with player sprinting on spot..I assumed my command of key space and x > greater than 0 would do it, but clearly wrong.

Thank you, very kind.

 

 

 

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

Ok.

I get away with myself...  ADHD for you and the bane of my life!

 

So,  the player moves the Trash man (player model) with W, A, S & D.

When moving normal, it's the walking animation and speed as shown in video.

When the player is pushing W the animation walk triggers,  if D is pushed the walk back animation plays.

When the Space Bar is pushed, a 'Sprint' mode is enabled,  so the animation changes to a sprint one and the player speed increases.  As per the video.

All working... OK (I think! ha).

When the player stands still pushing no keys, but the Space Bar the animation Sprint triggers and the model (player) is running on the spot..... which does not look right or feel right for a game.  I want the SPRINT animation to only trigger if space bar is pushed to sprint... and moving forward with W.....If the player stands still, pushing Space should do nothing.

Hope that makes sense, think I've confused myself!

Down the line, I'd like to add an animation for turning left and right with A & D keys.  But only when not moving, little subtle effects like this make game seem more quality.  hopefully that makes sense!?!?

 

Sorry if I've confused anyone and been making it harder than what it should be.

 

P.S Really freaking enjoy this Leadwerks stuff! 

P.P.S - Where in help document does it provide break down on thing like vectors, physics to pick stuff up (i.e do we need to activate a script to do the HL2 pick up physics shown in the FPS example? How do we make certain objects only enable pick up?  How do we do trigger load level / new level?

Sorry.. off a again 10000 ideas and questions coursing through my neurodiverse brain cells!

 

 

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

Sorry. Got so far, forgot to post code

 

 

--Public Values for Editor
Script.health = 100--int "Health"

--Private Values
Script.walkspeed = .02
Script.runspeed = 0.1


--Start script for starting once map loads, set player basic settings
function Script:Start()
	if self.entity:GetMass()== 0 then
		self.entity:SetMass(10) -- Char Controller default has mass 10. 0 means no physics at all.
	end
	self.entity:SetPhysicsMode(Entity.CharacterPhysics) --Setup character controller physics mode
	self.entity:SetCollisionType(Collision.Character, true)
	--Create game camera
	self.camera = Camera:Create()
	--Update the camera
	self:UpdateCamera()
end

--Adjust the camera for top down view on player
function Script:UpdateCamera()
	self.camera:SetRotation(90, 0, 0)
	self.camera:SetPosition(self.entity:GetPosition())
	self.camera:Move(0, 0, -4)
end

--[[State Machine - Setting State
function Script:SetMode(mode)
	if mode~= self.mode then
		self.mode = mode
			if mode=="idle" then
				--Put player in idle state / animation
				self.entity:PlayAnimation("Idle", .1, 200)
			elseif mode=="walk" then
					self.entity:PlayAnimation("Walk", 0.01, 200)
				--else
					--self:SetMode("idle")
			end
	end
end--]]

function Script:UpdateWorld()
	--Get the game window
	local window = Window:GetCurrent()
	--If the 'W' key is pressed move forward and play walk animation
	if window:KeyDown(Key.W) then
		self.entity:Move(Vec3(0, 0, -self.walkspeed))
		self.entity:PlayAnimation("Walk", .08, 100)
	elseif window:KeyDown(Key.S) then
		self.entity:Move(0, 0, .01)
		self.entity:PlayAnimation("Walkback", .06, 100)
	else
		self.entity:PlayAnimation("Idle", 0.7, 500)
	end

	if window:KeyDown(Key.A) then self.entity:Turn(0, -3, 0) end
	if window:KeyDown(Key.D) then self.entity:Turn(0, 3, 0) end

	if window:KeyDown(Key.Space) and window:KeyDown(Key.W) then
		self.walkspeed = self.runspeed
		self.entity:PlayAnimation("Run", .08, 200)
	else
		--self.entity:PlayAnimation("Idle", 0.7, 300)
		self.walkspeed = .02
	end
	--Update the camera each frame
	self:UpdateCamera()
end

 

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

16 hours ago, WazMeister said:

I want the SPRINT animation to only trigger if space bar is pushed to sprint... and moving forward with W.....If the player stands still, pushing Space should do nothing.

Try this:

 

if window:KeyHit(Key.Space) and window:KeyDown(Key.W) then 
-- add here the code for a jump 
end

 

And with the character controller it imay be preferable to use this:

https://www.leadwerks.com/learn?page=API-Reference_Object_Entity_SetInput

Look at the FPSPlayer.lua script

 

 

Link to comment
Share on other sites

Yes. I think that will work. When I'm. Home tonight, I'll give it a try.

Thanks for jumping in to respond. 

 

That new command you shared, I'll also check that out tonight.  What does it do,  should I replace my move commands with that command? 

 

 

  • Upvote 1

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

That example code for keydown. How does that even work? 

I understand the method of key being pressed is 1 or 0 and doing one key press minus the other will give results of 1 or - 1 and then * it by the speed wanted..  To move left or right. 

But how does that e, ample work with a variable holding the keydown state... Assuming a 1 or 0.. Then having and 1 and or 0... How does a variable holding 3 diffrent things and a maths function work? What is the keydown resulting in when pushed, I assume either 1 or 0?  Then the variable does multiplication?!?! 

 

 

((window:KeyDown(Key.Up) and 1 or 0) - (window:KeyDown(Key.Down) and 1 or 0))*4

 

  • Confused 1

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

I see.  So how does the move variable hold a bool, a 1 and a 0?

 

Or  does lua work in a way that the code is stating - If key down true then =1 and if false then = 0.  ???

So once it processes the above for Up and Down ,  it's basically presenting it as either

1 - 1 = 0

Or

1-0 =  1

Or

0-0 = 0

Or

0-1 = - 1

*4 is then moving player eiher up or down at a speed rate of 4.

 

Just trying to understand syntax really and how a variable can hold all of that and result as a 1 or 0 from keysown 1 and 0 statement. 

 

 

 

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

I think all you are asking for can be solved through studying the "FPSPlayer.lua" script, this is a work each one has to do to here to learn scripting possibilities.

This is an extract of this script:

Quote

 

    --Player Movement
    local movex=0
    local movez=0
    self.input[0]=0
    self.input[1]=0
    if window:KeyDown(Key.W) then self.input[1]=self.input[1]+1 end
    if window:KeyDown(Key.S) then self.input[1]=self.input[1]-1 end
    if window:KeyDown(Key.D) then self.input[0]=self.input[0]+1 end
    if window:KeyDown(Key.A) then self.input[0]=self.input[0]-1 end
    
    local playerMovement = Vec3(0)
    playerMovement.x = self.input[0] * self.moveSpeed
    playerMovement.z = self.input[1] * self.moveSpeed
    
    --This prevents "speed hack" strafing due to lazy programming
    if self.input[0]~=0 and self.input[1]~=0 then
        playerMovement = playerMovement * 0.70710678
    end

    --if self.entity:GetAirborne() then
    --    playerMovement = playerMovement * 0.2
    --end
    
    --Check for running with shift and when not carrying anything
    if self.carryingEntity == nil and window:KeyDown(Key.Shift) then
        playerMovement.z = playerMovement.z  * self.speedMultiplier
    end

    -- Check for jumping
    local jump = 0
    if window:KeyHit(Key.Space) and self:IsAirborne() == 0 then
        jump = self.jumpForce
        
        if self.sound.footsteps.concrete.jump ~= nil then
            self.sound.footsteps.concrete.jump:Play()
        end
        
        if self.weapons[self.currentweaponindex]~=nil then
            self.weapons[self.currentweaponindex]:BeginJump()
        end

        --Give the player an extra boost when jumping
        playerMovement = playerMovement * 1.6
    end

    self.entity:SetInput(self.camRotation.y, playerMovement.z, playerMovement.x, jump , false, 1.0, 0.5, true)
 

 

  • Thanks 1

 

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...