Hi everyone.
function lookingactivate_init(e)
end
function lookingactivate_main(e)
playerxang = g_PlayerAngX
playeryang = g_PlayerAngY
playerzang = g_PlayerAngZ
playerx = g_PlayerPosX
playery = g_PlayerPosY
playerz = g_PlayerPosZ
entityx = g_Entity[e]['x']
entityy = g_Entity[e]['y']
entityz = g_Entity[e]['z']
dist = GetPlayerDistance(e)
xlength = math.abs(playerx-entityx)
zlength = math.abs(playerz-entityz)
result = math.deg(math.atan2(xlength,zlength))
Prompt(result)
end
I write following the end of four hours of testing. What the above code does is about 10% of the way there.
What I want is to be able to tell whether the player is looking at a specific entity before offering the option to activate it or proceed to the next step. The current system offers no such command, therefore my idea was to work out the angle of the object compared to the player's position horizontally, then compare that to the angle of the player camera (which you can get). I've done that with a bit of trigonometry based on the known position of the player and the position of the entity.
So far I've got it working on the x axis only where I can tell my position in relation to the entity to within 90 degrees one way or the other. That's as far as I can get right now.
The theory would then be to take the angle the player is currently facing at and then subtract that from the entity's bearing in relation to the player, and if the result is less than 10 degrees or radians or whatever, offer the opportunity to press a button or have an event just happen. If you were looking to be even more precise you'd also do it vertically (or on the y axis) as well so the camera would have to be pointing roughly at the entity.
Unfortunately that's all just theory - can anyone tell me how to get this working properly or am I barking up the wrong tree completely?