SpiritMacardi Posted June 17, 2015 Share Posted June 17, 2015 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 Quote Link to comment Share on other sites More sharing options...
Rick Posted June 17, 2015 Share Posted June 17, 2015 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 Quote Link to comment Share on other sites More sharing options...
SpiritMacardi Posted June 17, 2015 Author Share Posted June 17, 2015 I hadn't gotten any errors, and I just tried your suggestion and I'm still not getting any results. Scratch that! I just got a working raycast by simply setting the GetPosition() commands to true! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.