I have mines out in my game, but they are only sometimes doing damage. There are no obstructing walls or other objects.
It's set up to raycast from the center of the explosion to the player and check if it finds the player - so that the explosion doesn't go through walls.
The problem I'm having is that I am often not able to get a hit to register. - but it does find a start and an end. Is there a minimum distance required for a raycast? Could it be because the player is moving?
Here is the part of my code that gets the startPos (position of the mine) and the endPos is at the player for a raycast.
local startPos = center --- location of mine
local endPos = player:GetWorldPosition() + player:GetWorldTransform():GetUpVector()*50
print("startPos: ", startPos)
print("endPos: ", endPos)
local hit = World.Raycast(startPos, endPos)
if (hit == nil) then
print("hit is nil")
elseif (hit.other == nil) then
print("hit other is nil")
elseif (hit.other ~= player) then
print("hit other is not player")
end
if(hit ~= nil and hit.other ~= nil and hit.other == player) then
print("player hit:", player.name)
-- apply damage
end
Sometimes it detects a hit and sometimes it doesn't. Below is what printed out from that after running over the mines. Only 2 say player hit.
Most say hit is nil.
startPos: X=421.777 Y=-1101.906 Z=-0.500
endPos: X=353.075 Y=-1049.293 Z=151.931
hit is nil
startPos: X=896.615 Y=-847.272 Z=-0.500
endPos: X=907.623 Y=-918.088 Z=151.931
player hit: Bot1
startPos: X=1352.508 Y=-608.237 Z=-0.500
endPos: X=1417.427 Y=-605.847 Z=151.931
hit is nil
startPos: X=89.154 Y=175.976 Z=-0.500
endPos: X=156.415 Y=130.417 Z=151.931
hit is nil
startPos: X=-612.749 Y=459.474 Z=-0.500
endPos: X=-549.406 Y=427.239 Z=151.931
hit is nil
startPos: X=-1102.584 Y=-539.945 Z=-0.500
endPos: X=-1073.672 Y=-465.573 Z=151.931
player hit: Bot1
I'm having a hard time figuring out what could cause the hit to be nil.
Could it be because the player is running in combination with lag? I'm using multiplayer preview mode.