Category | Scripting |
Created | 17.07.2010 13:28 |
Russell Peterson (Unknown) | 17.07.2010 13:30 |
---|---|
We've got a big of a bug with a function we created, RenderWorldText, which renders a string of text on the screen using a world position: function renderWorldText(x,y,z, height, text) --Convert the world into screen x, y, z = project(x,y,z); setTextAlignment(RenderText.ALIGN_CENTER); renderText(x,y, height, text); setTextAlignment(RenderText.ALIGN_LEFT); end; And we're calling it like this: if self.nearestVehicle ~= nil and self.currentVehicle == nil then local x,y,z = getWorldTranslation(self.nearestVehicle.rootNode); renderWorldText(x,y+1.5,z, 0.03,"Press E to Drive"); end; What I'm trying to do is render the "Press E To Drive" at the vehicle's location when the player is near. However, if you stand near a vehicle, then look in the opposite direction, the text is rendered again in front of you. If you look left or right, you can't see it. It only happens when you look the exact opposite direction of the vehicle. Is this a bug with the Project function or is it our code? |
Stefan Geiger - GIANTS Software | 20.07.2010 10:27 |
---|---|
This is due to way the projection works. You need to check for the projected z value to be negative, then the point is in front of the camera. So you can write: project... if z < 0 then renderText... end |
Russell Peterson (Unknown) | 22.07.2010 20:15 |
---|---|
Thanks for your help. In my tests I found Z is always positive, between 0.9 and 1.05. So I set it to: if z < 1 then render... end And this is working great! |
Note: Log in to post. Create a new account here.