Molamar Posted May 10, 2018 Share Posted May 10, 2018 Hello@all, according to Aggror Project Saturn Tutorial about the implementation of a enemy turret, i have some problems with the raycast detections and the collision types. the scene is setup with the fpsplayer prefab, some csg shapes and the fpsautopistol.mdl with a directional light as muzzlefash. i enhanced the turret script with additional informations from pickinfo class if(self.fireRateTimer > self.fireRate) then local pickinfo = PickInfo() local source = self.entity:GetPosition() local target = Transform:Point(Vec3(0,0,self.WeaponRange),self.entity,nil) if (self.entity.world:Pick(source, target, pickinfo, 0, true, Collision.Prop)) then local text = pickinfo.entity:GetKeyValue("name","default") --the object that was picked local hit = pickinfo.entity:GetPosition(true) -- the global position of the object local point = self.entity:GetPosition() -- the position of the turret local dis = point:DistanceToPoint(hit) --the distance from turret to the object System:Print(hit) System:Print(text) System:Print(dis) pickinfo.entity:Hide() --so when the entity itself is disappearing, i can figure out which it is ;) end When the turret is doing the pick operation the informations which are stored in the hit, point, dis variables looks fine for me, just the text returns "default".(this means the entity has no name property) My FpsPlayer has a name assigned, so i guess whatever the pick is hitting, it is not the fpsplayer. i extented the script with the line: pickinfo.entity:Hide() and the first "pick" hits something and after second "pick" the csg shape below my charctercontroller disappers How can i figure out what was picked(for curiosity) and then doing the correct collision type for the raycast only intersect with the character controller. i remember there was table with the collision types but i couldnt find it. Thanks for any help Quote Link to comment Share on other sites More sharing options...
macklebee Posted May 10, 2018 Share Posted May 10, 2018 Here is the table that for some reason has been removed from the documentation: If you are trying to only have a collision with the character then you will need to make a new collision type that only interacts with a character using SetResponse(). Then use that new collsiontype with your Pick. See this post for more info: Quote 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 More sharing options...
Molamar Posted May 11, 2018 Author Share Posted May 11, 2018 Thx for your help, i´m half way there i guess, but stumbling the last steps. SetResponse() is also not documented, or is it me? Anyway, i wrote the Collision:SetResponse(10, Collision.Character, Collision.Collide) in the start function of the turret script. The same script contains if (self.entity.world:Pick(source, target, pickinfo, 0, true, 10)) then is the pick operation in the updateworld function the self.entity:SetCollisionType(10) is for my case not necessary ? Because the character model should stay as collision type character and the pick ray is defined as type 10. I´ve tried some constellations how to setup the scripts, but it still dont work. Quote Link to comment Share on other sites More sharing options...
macklebee Posted May 12, 2018 Share Posted May 12, 2018 SetResponse is not officially documented for some reason but if you search the forum you will find plenty of examples of it. What you are showing should work assuming the endpoints of the World Pick are where you think they are. You may need to place a sphere at the pick position to confirm. Another way to do this would be just pick everything by setting the Pick's collisiontype to '0' then filtering the results by checking the collisiontype/name/etc of the picked entity. Example: window = Window:Create() context = Context:Create(window) world = World:Create() camera = Camera:Create() camera:Move(0,1,-5) light = DirectionalLight:Create() light:SetRotation(35,35,0) enemy = Model:Load("Models/Characters/generic/generic.mdl") enemy:SetPosition(-4,0,0) enemy:SetRotation(0,90,0) enemy:SetColor(1,.5,0,1) enemy:SetCollisionType(Collision.Character) player = Model:Load("Models/Characters/generic/generic.mdl") player:SetPosition(4,0,0) player:SetColor(0,1,0,1) player:SetCollisionType(Collision.Character) player.health = 1000 wall = Model:Box() wall:SetScale(0.2,1,1) wall:SetColor(0,0,1,1) wall:SetCollisionType(Collision.Prop) toggle1 = 1 toggle2 = -1 while window:KeyDown(Key.Escape)==false do if window:Closed() then break end if wall:GetPosition().y > 3 then toggle1 = -1 elseif wall:GetPosition().y < -1 then toggle1 = 1 end wall:Translate(0,0.01*Time:GetSpeed()*toggle1,0) if player:GetPosition().y > 3 then toggle2 = -1 elseif player:GetPosition().y < -1 then toggle2 = 1 end player:Translate(0,0.02*Time:GetSpeed()*toggle2,0) Time:Update() world:Update() world:Render() pickinfo = PickInfo() p0 = enemy:GetPosition() -- enemy position p1 = p0 + Vec3(0,1.7,0) -- adding height so ray comes from enemy eyes p2 = player:GetPosition() p3 = p1 + Vec3(10,0,0) -- 10m ray out from enemy eyes pick = world:Pick(p1,p3,pickinfo,0,true,0) -- pick between two defined points if pick then if pickinfo.entity==player then player.health = player.health - 0.1 end --do damage to player d1 = camera:Project(pickinfo.position) -- just to show raycast hitpoint end d0 = camera:Project(p1) -- just to show raycast startpoint context:SetBlendMode(Blend.Alpha) context:SetColor(1,0,0,1) context:DrawText(string.format("Player Health: %.1f",player.health), 2, 2) context:DrawText("Pick: "..string.format("%s", pick),0,20) n0 = camera:Project(p0) n1 = camera:Project(p2) context:DrawText("ENEMY",n0.x,n0.y) context:DrawText("PLAYER",n1.x,n1.y) if pick then context:DrawLine(d0.x,d0.y,d1.x,d1.y) end context:SetColor(1,1,1,1) context:SetBlendMode(Blend.Solid) context:Sync(true) end 1 1 Quote 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 More sharing options...
Molamar Posted May 14, 2018 Author Share Posted May 14, 2018 Thx for the detailed information and example. it works now 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.