Jump to content

turret LOS issue, please help if able


Gamer4Life
 Share

Recommended Posts

Heya, everyone. I was wondering if someone can help me fix this problem i'm having. I am trying to create a turret that targets someone when they come in range of it and shoots them. I got all that working fine, but this turret can shoot through walls. I was wondering if someone had any idea what I need to change on the walls, or the code to enable a Line of Sight factor. This is the script atm i'm using.

 

Script.aimingLocation = "" --entity "Aiming Location"

Script.rotSpeed = .1 --float "Rotation Speed"

Script.fireRate = .1 --float "Fire rate"

Script.fireRateTimer = 0

Script.muzzleFlashLight = "" --entity "Muzzle flash light"

Script.muzzleTime = 0.1 --float "MuzzleTimer"

Script.muzzleTimer = 0

Script.gunFireSoundPath = "" --path "Fire Sound" Wav file (*wav):wav|Sound"

Script.gunFireSoundFile = nil

Script.fireRange = 15 --float "Fire range"

Script.damage = 5 --float "Damage per bullet"

 

 

function Script:Start()

self.muzzleFlashLight:Hide()

if self.gunFireSoundPath ~= "" then

self.gunFireSoundFile = Sound:Load(self.gunFireSoundPath)

end

end

 

function Script:UpdateWorld()

--fire rate

self.fireRateTimer = self.fireRateTimer + (Time:GetSpeed()/100)

self.muzzleTimer = self.muzzleTimer + (Time:GetSpeed()/100)

--get positions

local turretPos = self.entity:GetPosition()

local playerPos = self.aimingLocation:GetPosition(true)

 

--is target in range?

if(turretPos:DistanceToPoint(playerPos) <= self.fireRange) then

--rotate turret toward target

self.entity:Point(self.aimingLocation, 2, Time:GetSpeed() * self.rotSpeed)

--allow firing

if(self.fireRateTimer > self.fireRate) then

local pickInfo = PickInfo()

local point2 = Transform:Point(0,0,self.fireRange, self.entity, nil)

 

if (self.entity.world:Pick(turretPos, point2 ,pickInfo, 0, true, Collision.Prop)) then

self.aimingLocation:GetParent().script:Hurt(self.damage)

end

 

self.muzzleFlashLight:Show()

self.muzzleTimer = 0

self.fireRateTimer = 0

self.gunFireSoundFile:Play()

end

end

 

if(self.muzzleTimer > self.muzzleTime) then

self.muzzleFlashLight:Hide()

self.muzzleTimer = 0

end

end

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