Jump to content

Leadwerks 5 beta first-person shooter template


Josh

1,852 views

 Share

The best way to test the new engine is to use it to make something. I am messing around with the beginnings of a new first-person shooter template. I'm telling everyone involved "We are remaking Doom, but a little differently" and it actually works really well. Everyone understand what it should look like, and there is no need to establish a new visual style. We can tell when we have it right, and when we have it wrong. And the original game gives us a sort of benchmark for quality and performance we can measure against.

I have two scripts for the player. One is for basic movement and interaction with objects. Another one handles the display and movement of the player's weapon. I opted to use entirely programmatic motion for the weapon sway, and I don't plan on showing any hands. These will work together because Leadwerks 5 allows you to add multiple scripts to any entity. Here is the current weapon script:

function Script:Start()

	self.modelfile = "Models/Weapons/Ronan Rifle/scene.gltf"
	self.weaponposition = Vec3(0.12, -0.4, 0.42)
	self.weaponswayspeed = 0.25
	self.weaponswayticks = 0
	
	--Load weapon
	self.weapon = LoadModel(self.world, self.modelfile)
	if self.weapon == nil then return end
	self.weapon:CastShadows(false)
	self.weapon:SetPosition(self.weaponposition)
	self.weaponrotation = self.weapon:GetRotation()
	
end

function Script:Update()

	if self.weapon == nil then return end

	--Parent to camera if not already done
	if self.weapon.parent == nil then
		if type(self.camera) == "userdata" then
			self.weapon:SetParent(self.camera,false)
		else
			DebugWarning("FPSWeapon: self.camera must be an entity.")
		end
	end

	--Adjust speed based on ground velocity
	self.weaponswayspeed = 0.1
	if self:GetAirborne() == false then
		local speed = self.velocity.xz:Length()
		self.weaponswayspeed = self.weaponswayspeed + 0.75 * math.min(speed / 3, 1)	
	end
	
	--Weapon sway
	self.weaponswayticks = self.weaponswayticks + 16.666666 * self.weaponswayspeed
	local pitch = math.cos(self.weaponswayticks / 100) * 0.25
	local yaw = math.sin(self.weaponswayticks / 100) * 0.25
	local sway = math.sin(self.weaponswayticks / 100) * 0.004
	local bob = -math.cos(self.weaponswayticks / 50) * 0.002
	self.weapon:SetRotation(self.weaponrotation + Vec3(pitch, yaw, 0))
	self.weapon:SetPosition(self.weaponposition + Vec3(sway, bob, 0))

end

An interesting bit is the swizzle and properties, which makes Lua more flexible than in the past:

local speed = self.velocity.xz:Length()

In Leadwerks 4 we would have had to type all this:

local speed = self.entity:GetVelocity():xz():Length()

Here is the very first pass, with some materials courtesy of @TWahl. I wanted much faster movement with this one, so the player runs by default and you hold the shift key to walk more slowly.

 

  • Like 6
 Share

3 Comments


Recommended Comments

That run seems like a rapid walk to me and the walk seems a bit slow (but maybe those were the speeds in Doom too, I forget).  Looks great otherwise.

  • Like 1
  • Thanks 1
Link to comment
5 hours ago, Genebris said:

Very nice! But why is FPS so low?

I think the screen recorder locks it at 60.

Link to comment
Guest
Add a comment...

×   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.

×
×
  • Create New...