Jump to content

Raycast not functioning


SpiritMacardi
 Share

Recommended Posts

First of all, hey everyone! I'm new to the forums, and I've been using/learning Leadwerks since the beginning of this year. It's been my first ever experience with making games, and I love how easy to use the engine is.

 

Anyway, I've hit a bit of a snag in my current endeavors. Basically, I'm trying to have it so that the character of my game attacks using a sphere that appears, moves forward a set amount, and then returns and vanishes once more. To detect a hit, I figured it would make sense to have a raycast that projects from the start point of the sphere out to its current position, but it fails to detect anything. I'll leave a copy of my code below, and hopefully someone will be able to tell me what I'm doing wrong and how I can correct it.

 

Script.player = "" --entity "Player"
Script.ringStart = "" --entity "Start position"
Script.ringEnd = "" --entity "End position"
function Script:Start()
self.returning = false
self.entity:Hide()
end
function Script:UpdatePhysics()
local pickinfo = PickInfo()
if self.entity:Hidden() == false then

 if self.returning == false then

  if self.entity:GetDistance(self.ringEnd) < 0.1 then

   self.returning = true

  else

   self.entity:Move(0.1, 0, 0)

   local bulletPos = self.entity:GetPosition(false)
   local startPos = self.ringStart:GetPosition(false)

   if (self.entity.world:Pick(bulletPos, startPos, pickinfo, 0, false)) then

 System:Print("Part 1 working")

   end

  end

 end

 if self.returning == true then

  if self.entity:GetDistance(self.ringStart) < 0.1 then

   self.returning = false
   self.entity:Hide()

  else

   self.entity:Move(-0.1, 0, 0)

  end

 end

end
end

Link to comment
Share on other sites

self.entity.world

 

That part looks strange. Are you getting an error? I've never checked to see if self.entity had a world variable in it. I would think it wouldn't. Usually you could get the current world at the top of your function or store it in a variable in start.

 


function Script:UpdateWorld()
 local world = World:GetCurrent()

-- now use world:Pick()
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...