Jump to content
  • entries
    14
  • comments
    29
  • views
    12,359

Behind Enemy Lines


burgelkat

2,387 views

 Share

Hi,

the last weeks in office are very bussy. But today i have some time to work on my project.

In Akt 3 i  would imlement a Mortar.

I found a nice free model that i rework in blender and exported as mdl file

also i searched for some sounds and mixed them together.

For the sound i use "Audacity" becaus i get some errors in leadwerks with this sound i converted sounds with "Audio online converter"

then i work on the scirpts.

i use some parts from einlanders grenade script. and changed the projectile script and saved it to Mortal Ammo script.

at the moment it is a little buggy and i dont know what i have to chage. i think the problem is in this part:

                                        if bullet~=nil then												
                                                bullet:Show()
												bullet:SetFriction(10000,10000)
												bullet:SetCollisionType(Collision.Projectile)
                                                bullet:SetPosition(self.muzzle:GetPosition(true),true)
                                                bullet:SetRotation(self.muzzle:GetRotation(true),true)
												bullet:SetMass(1)
												Force = Vec3(0,3000,0)
												bullet:AddForce(Force)
                                                if bullet.script~=nil then
                                                        bullet.script.owner = self
                                                        if type(bullet.script.Enable)=="function" then
                                                                bullet.script:Enable()
                                                        end
                                                        bullet:Turn(Math:Random(-3,3),Math:Random(-3,3),0)

the bullet is not always transformed into an explosion when it hits the ground. If it hits the player, then it always works.

 

here is the result. Sometimes it is funny how crazy the bullet goes. But now i have to look video with my daughter so i will work later on it. :D

if anyone knows how i align the force at the distance of the player, about help or hints i would be glad.

Also on a note why the bullet does not always explode on the ground, I would be glad. As always sorry for my english. By the way Act 3 is progressing. Below are a few pictures.

 

 

screenshot61.jpg

screenshot62.jpg

  • Like 3
 Share

3 Comments


Recommended Comments

Looks nice. 

as for the projectile not directly exploding: without seeing the script for the projectile we can only gues.

As for the force to apply. Since you use an angular mortar, all you need to do is play with the angle you fire and the maximum fire power.

  • First experiment with the angle of the mortar. With a force of 1000, which angle will get you the furthest? 
  • When you have gotten the furthest distance, ask yourself if this is the maximum required distance of the mortar.
  • Adjust the force of the mortar to match the maximum distance.
  • As for a basic adjustment. Try something like this (I haven't tried it):
    • Force is 1000
    • Lets say an angle of 45 gives you a distance of 80 meters
    • Lets say an angle of 80 gives you a distance of 10 meters
    • If an enemy is at 60 meters: 
      • 80-10 = 70. (max dist-shortest dist = gapDist)
      • 60-10=  50. (enemy dist - shortest dist = distRange)
      • 50/70=0.7. (distRange / gapDist = distRatio)
      • 80-45 = 35 (maxAngle - minAngle = angleGap)
      • 35* 0.7 = 24.5 (angleGap * distRatio = additionalAngle)
      • 24.5 + 45= 70.5 (additionalAngle + minAngle = newAngle)
    • You can add an additional random value to the force or the angle to get some more random results.
  • Like 2
Link to comment

thanks Aggror for this hint i think  i know where i can do this in the script.

by the way thats the prjectile script:

Script.movespeed=1000
Script.pickradius=0
Script.damage=10
Script.lifetime=20000
Script.enabled=false--bool "Enabled"

function Script:Start()
	self.sound={}	
	self.sound.ricochet={}
	self.sound.ricochet[1]=Sound:Load("Sound/Weapons/Explosion.wav")
	self.sound.ricochet[2]=Sound:Load("Sound/Weapons/Explosion.wav")
	self.sound.ricochet[3]=Sound:Load("Sound/Weapons/Explosion.wav")
	self.starttime=Time:GetCurrent()
	self.emitter={}
	
	--Debris emitter - This will throw chunks off of walls and make it look like they are breaking
	self.emitter[0]=Emitter:Create()
	self.emitter[0]:SetCollisionType(Collision.Prop)--Enables particle bouncing
	self.emitter[0]:SetMaterial("Materials/Effects/smoke.mat")
	self.emitter[0]:SetEmissionVolume(0.05,0.05,0.05)	
	self.emitter[0]:SetColor(0.1,0.1,0.1,1)
	self.emitter[0]:SetVelocity(5.5,15,5.5,1)
	self.emitter[0]:SetParticleCount(5)
	self.emitter[0]:SetReleaseQuantity(5)
	self.emitter[0]:SetMaxScale(0.9)
	self.emitter[0]:SetDuration(1500)
	self.emitter[0]:SetAcceleration(0,-12,0)
	self.emitter[0]:SetLoopMode(false)
	self.emitter[0]:Hide()
	
	--Smoke emitter - This will provide a soft dust effect around bullet impacts
	self.emitter[1]=Emitter:Create()
	self.emitter[1]:SetColor(1,1,1,0.25)
	self.emitter[1]:SetMaterial("Materials/Effects/smoke.mat")
	self.emitter[1]:SetEmissionVolume(0.1,0.1,0.1)
	self.emitter[1]:SetVelocity(0.3,0.3,0.3,1)
	self.emitter[1]:SetParticleCount(8)
	self.emitter[1]:SetReleaseQuantity(3)
	self.emitter[1]:SetMaxScale(15)
	self.emitter[1]:SetDuration(3800)
	self.emitter[1]:AddScaleControlPoint(0,0.5)
	self.emitter[1]:AddScaleControlPoint(1,1)
	self.emitter[1]:SetRotationSpeed(10)
	self.emitter[1]:SetLoopMode(false)
	self.emitter[1]:Hide()
	
	--Smoke emitter - This will provide a soft dust effect around bullet impacts
	self.emitter[2]=Emitter:Create()
	self.emitter[2]:SetColor(1,1,1,0.25)
	self.emitter[2]:SetMaterial("Prefabs/Effects/Explosion/explosion.mat")
	self.emitter[2]:SetEmissionVolume(0.1,0.1,0.1)
	self.emitter[2]:SetVelocity(0.3,0.3,0.3,1)
	self.emitter[2]:SetParticleCount(1)
	self.emitter[2]:SetReleaseQuantity(1)
	self.emitter[2]:SetMaxScale(25)
	self.emitter[2]:SetDuration(2500)
	self.emitter[2]:AddScaleControlPoint(0,0.5)
	self.emitter[2]:AddScaleControlPoint(1,1)
	--self.emitter[2]:SetRotationSpeed(10)
	self.emitter[2]:SetLoopMode(false)
	self.emitter[2]:Hide()
end

function Script:Enable()--in
	if self.enabled==false then
		self.enabled=true
	end
end

function Script:FindScriptedParent(entity,func)
	while entity~=nil do
		if entity.script then
			if type(entity.script[func])=="function" then
				return entity
			end
		end
		entity = entity:GetParent()
	end
	return nil
end

function Script:UpdateWorld()
	if self.enabled==false then return end
	if self.entity:Hidden() then return end
	local pickinfo=PickInfo()	
	local pos = self.entity:GetPosition(true)
	local targetpos = Transform:Point(0,0,self.movespeed/60.0 * Time:GetSpeed(),self.entity,nil)
	local result = self.entity.world:Pick(pos,targetpos,pickinfo,self.pickradius,true,Collision.Projectile)
	if result then
		local enemy = self:FindScriptedParent(pickinfo.entity,"Hurt")
		if enemy then
			if self.owner then
				--if self.owner.teamid==enemy.script.teamid then
				--	result=false
				--end
			end
			if result then
				if enemy.script.health>0 then
					enemy.script:Hurt(self.damage,self.owner)
				end
			end	
		end
		if result then
			self:Explode()
			--Bullet mark decal
			local mtl
			local scale = 2
			if enemy~=nil then
				mtl = Material:Load("Materials/Decals/wound.mat")
				scale = 0.1
			else
				if pickinfo.surface~=nil then
					local pickedmaterial = pickinfo.surface:GetMaterial()
					if pickedmaterial~=nil then
						rendermode = pickedmaterial:GetDecalMode()
					end
				end
				mtl = Material:Load("Materials/Decals/BombCrater.mat")
			end
			local decal = Decal:Create(mtl)
			decal:AlignToVector(pickinfo.normal,2)
			decal:Turn(0,0,Math:Random(0,360))
			decal:SetScript("Scripts/Objects/Effects/BulletMark.lua")
			if mtl~=nil then mtl:Release() end
			decal:SetPosition(pickinfo.position)
			decal:SetParent(pickinfo.entity)
			
			--Apply global scaling
			local mat = decal:GetMatrix()
			mat[0] = mat[0]:Normalize() * scale
			mat[1] = mat[1]:Normalize() * scale
			mat[2] = mat[2]:Normalize() * scale	
			decal:SetMatrix(mat)
			decal:EmitSound(self.sound.ricochet[math.random(#self.sound.ricochet)],30)

			self.entity:Release()
		else
			self.entity:SetPosition(targetpos)
		end
	else
		self.entity:SetPosition(targetpos)
	end
	if Time:GetCurrent()-self.starttime>self.lifetime then
		self.entity:Release()
	end
end

function Script:Explode()	
	self.emitter[0]:Show()
	self.emitter[0]:SetPosition(self.entity:GetPosition(true))
	self.emitter[0]:Reset()
	self.emitter[0]:Play()	
	self.emitter[1]:Show()
	self.emitter[1]:Reset()
	self.emitter[1]:SetPosition(self.entity:GetPosition(true))
	self.emitter[1]:Play()
	self.emitter[2]:Show()
	self.emitter[2]:Reset()
	self.emitter[2]:SetPosition(self.entity:GetPosition(true))
	self.emitter[2]:Play()
end

 

Link to comment

So the mortar scripts works with a raycast to detect impact. 

What you can do is trying to find out where the raycast is going.You can store the origin and target of the raycast and draw a line between them

self.pos = self.entity:GetPosition(true)
self.targetpos = Transform:Point(0,0,self.movespeed/60.0 * Time:GetSpeed(),self.entity,nil)

function Script:PostRender(context)
	--You need a camera refernce in this script.
	local p1 = camera:UnProject(self.pos)
	local p2 = camera:UnProject(self.targetPos)
	context:DrawLine(p1.x, p1.y, p2.x, p2.y)
end

 

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