Jump to content

Raycasting help


zebn
 Share

Recommended Posts

Hey guys.

 

Im trying to make game, but got a problem

 

I wrote a function, that change color of object "buildable" to red on click via function DoPick(Win)

 

but it works fine only for first 5 seconds

 

after ~5 sec it didnt do anything

 

mb some overflow?

 

I dont know, please help

 

function Script:Start()
-- Pivot Settings
self.initPos = self.entity:GetPosition(true)
self.initAngle = self.entity:GetRotation(true)
self.moveSpeed = 0.2
self.moveMultiplier = 2
self.turnSpeed = 0.4
self.yOffset = 1.0
self.entity:SetPosition(self.initPos.x, self.initPos.y + self.yOffset, self.initPos.z)
-- Camera Settings
self.cam = Camera:Create(self.entity)
self.camInitPos = Vec3(0, 7, -8)
self.cam:SetPosition(self.camInitPos)
self.zoomIn = 2
self.zoomOut = 25
self.cam:Point(self.entity)
-- Pick Settings
self.pickRadius = 0.2
self.pickedActor = nil
end

function Script:UpdateWorld()

local Win = Window:GetCurrent()
local Ts = Time:GetSpeed()
local smp = 1

if Win:MouseHit(1) then
self:DoPick(Win)
end

end

function Script:DoPick(Win)
local pickInfo = PickInfo()
local mp = Win:GetMousePosition()
if self.cam:Pick(mp.x, mp.y, pickInfo, self.pickRadius, true) then
if pickInfo.entity.entiType == entiTypes.buildable then
pickInfo.entity:SetColor(255,0,0)
end
else
end
end
end


 

774e0a8982.png

Link to comment
Share on other sites

Just a side note - SetColor() uses a 0-1 scale - as does the rest of LE's color properties/commands as of a few months ago. The only thing that still uses the 0-255 scale is the actual color picker window, but it actually returns a 0-1 scale and requires a 0-1 scale to set it via code. Anything over 1 just essentially increases the intensity but you will probably not notice a difference past a value of 2 (if not less than that).

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

well, Im pretty sure something bad with my Pick or PickInfo

 

It marks 2-5 objects, and after that it stops marking, but program works fine

 

looks like oberflow, but I cant see which variable overflowing

 

 

function Script:Start()
-- Pivot Settings
self.initPos = self.entity:GetPosition(true)
self.initAngle = self.entity:GetRotation(true)
self.moveSpeed = 0.2
self.moveMultiplier = 2
self.turnSpeed = 0.4
self.yOffset = 1.0
self.entity:SetPosition(self.initPos.x, self.initPos.y + self.yOffset, self.initPos.z)
-- Camera Settings
self.cam = Camera:Create(self.entity)
self.camInitPos = Vec3(0, 7, -8)
self.cam:SetPosition(self.camInitPos)
self.zoomIn = 2
self.zoomOut = 25
self.cam:Point(self.entity)
-- Pick Settings
self.pickRadius = 0.2
self.pickedActor = nil
end

function Script:UpdateWorld()

local Win = Window:GetCurrent()
local Ts = Time:GetSpeed()
local smp = 1

if Win:MouseHit(1) then
self:DoPick(Win)
end

end

function Script:DoPick(Win)
local pickInfo = PickInfo()
local mp = Win:GetMousePosition()
if self.cam:Pick(mp.x, mp.y, pickInfo, self.pickRadius, true) then
if pickInfo.entity.entiType == entiTypes.buildable then
pickInfo.entity:SetColor(255,0,0)
end
else
end
end
end


 

774e0a8982.png

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