Help with rendering sprites after certain distance away
4 replies, posted
I am trying to make a system when the player is X distance away from an entity it disapears and a sprite replaces it.
this is what i have so far:
function ENT:Think( ply )
self.Entity:SetNoDraw( true )
hook.Add( "HUDPaint", "paintsprites", function()
sprite1=Material( "sprite1" )
Vector1 = self.Entity:GetPos()
Vector1.z = Vector1.z+75
cam.Start3D(EyePos(),EyeAngles())
render.SetMaterial( sprite1 )
render.DrawSprite( Vector1, 128, 128, Color(255, 255, 255, 255) )
cam.End3D()
end)
end
I am having 2 problems with this script.
1. I do not know how to set up Vector:Distance for an entity, so that i can make it appear and disappear properly.
2. when i have more then one entity only the new one has the sprite on it.
anything would help me right now i have been trying to figure out a way to get it to work all day.
Update: after experimenting with the code i found out i could use self.Entity:EntIndex() to call each rendering by a different name.
therefor allowing me to render more then one at a time.
i still however are having problems figureing out how to get the distance from the player to the entity .
this is what i have so far on that:
"function ENT:Think( ply )
local self = LocalPlayer():GetPos()
local ent = self.Entity:GetPos()
distance = self:Distance( ent )
if distance >= 500 then
self.Entity:SetNoDraw( true )
else
self.Entity:SetNoDraw( false )
end
end"
however i get an error at line 3 with self.entity:getpos()
Anyone know how to get this to work?
[lua]
function ENT:Draw( )
if self:GetPos( ):Distance( EyePos( ) ) > 500 then
--draw sprite here
else
self:DrawModel( )
end
end
[/lua]
Something like that. You should use render.DrawSprite or whatever the function is to draw the sprite.
Thank you so much i was about to lose all hope!
final question on sprites how can i make it so i don't see the sprite through a wall or through my weapon?
Uhm, the material requires certain flags I think. Not sure which ones, though.
Sorry, you need to Log In to post a reply to this thread.