Jump to content

tipforeveryone

Members
  • Posts

    382
  • Joined

  • Last visited

Posts posted by tipforeveryone

  1. I am trying to build a Top view shooting game

    First I use Camera:Pick to get collided position by Mouse pointer to Terrain, everything ok, System:Print() can make output of collided position

    --set shooting point follow mouse cursor
    mousepos = window:GetMousePosition()
    mousePickInfo = PickInfo()
    if camera:Pick(mousepos.x,mousepos.y,mousePickInfo,0,true,Collision.LineOfSight) then
    	shootingPoint:SetPosition(mousePickInfo.position)
      	--shootingPoint is a pivot which I created in Script:Start()
    	System:Print(mousePickInfo.position)
    end

    Then I create a ray from player position to mousePickInfo.position then there is problem, the ray can not collide some areas of terrain and return 0,0,0 position, a height map was imported to construct terrain

    bulletPickInfo = PickInfo()
    world:Pick(
    	body:GetPosition(true),
    	mousePickInfo.position,
    	bulletPickInfo,0.2,true,Collision.LineOfSight
    )

    I use a context:DrawLine to visualize the ray, and here the video, notice that when I move the mouse, sometime the red line changes its end point

     

  2. I use this for my weapon blocking (by wall) system, I think it will work with your camera

    • You can calculate the distance between the pickInfo.position and the entity which you put start of Pick (Beam Point 1) 
    • then use the maximum range of your camera to player (self.defaultCameraRange) minus that, you get the distance between MaxRange to pickInfo.position (called self.collisionMinusRange)
    • Because camera point its Z axis to player, so that you can use entity:Move(0,0,self.collisionMinusRange)
    • In the meantime, Use camera:SetPosition(self.beamPoint2:GetPosition(true)) to keep you camera at the maxRange when not collided any obstacle

    Hope you can understand what I am trying to explain :D

    image.png.f2abfb15507bd33047188a891acc8494.png

    • Like 1
    • Thanks 2
  3. I have a small function which can help you to define if an entity is inside a cone view of another entity.

    function CheckConeView(axis,entity,target,angle)
    	local z,u
    	if axis == "x" then z = Transform:Point(Vec3(1,0,0),entity,nil)
    	elseif axis == "y" then z = Transform:Point(Vec3(0,1,0),entity,nil)
    	elseif axis == "z" then z = Transform:Point(Vec3(0,0,1),entity,nil)
    	end
    	u = Transform:Point(target:GetPosition(true),nil,entity)
    	z = Transform:Point(z,nil,entity)
    	local targetAngle = Math:ACos(u:Dot(z)/(u:Length()*z:Length()))
    	if targetAngle < angle/2 then return true else return false end
    end

    This should be made as global function, then you can use this as below

    function Script:PostRender()
    	if CheckConeView("z",self.yourPlayerCamera,self.target,90) and self.targetInRange == true then
    		--display health bar code
    	end
    end

    hope this make your idea possible :)

  4. I use a material which has all 3 textures: diffuse, normal, specular then add ssr.shader to my camera

    As I expect, the reflection should follow specular map to reflect scene around my object, but it doesn't. When ssr was enabled, everything was reflected on that object's face.

    Adjust RGB value of Specular is the only one way to control how much reflection on that object

    image.png.41f3e30740b44da9f253bc2fc92e5d13.png

    But when it comes almost black (to reduce reflection) specular map becomes more useless

    Is there any way to really control ssr with specular map ?

  5. You can create a simple function which helps you to convert 0-255 to 0-1

    function rgba(r,g,b,a) --red green blue alpha, it is like CSS
    	local rgba_value = Vec4(r/255,g/255,b/255,a)
    	return rgba_value
    end
    
    --make this function global then you can use entity:SetColor(rgba(142,36,64,0.8))

     

     

    • Upvote 1
×
×
  • Create New...