Scripts / Directional script?

Author
Message
Dralel
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 4th Nov 2013
Location: UK
Posted: 29th May 2014 14:26 Edited at: 29th May 2014 14:42
I am fooling around with a prompt script, I have it fully working, where the player presses E next to an object and a text prompt appears. What I want is that the prompt only appears if the player is looking directly at the item and then presses E. Is this possible?



Fyi, this is the code I have thus far:





ALSO, two questions:



1. Can I change the font type, size, colour etc within LUA/FPSCR?



2. Can I freeze the game whilst the prompt appears?



Thanks alot. (I have next to zero coding knowledge)

GPU: GTX 660, CPU: i7 3770 Intel 3.40ghz x4, PSU: 650 Watt, RAM: 8GB DDR3, OS: Win7 Ultimate 64-bit
PM
Auger
13
Years of Service
User Offline
Joined: 21st Aug 2011
Location: Out There
Posted: 30th May 2014 06:48
Would be fairly simple for someone with some 3d math (not me ) You'd need to find the angle between two 3d vectors.
tomjscott
User Banned
Posted: 30th May 2014 22:35
Quote: "Would be fairly simple for someone with some 3d math (not me ) You'd need to find the angle between two 3d vectors."




Except for one problem. The player's vector is unknown. Unless there are as yet unknown g_Entity[e] attributes we haven't been told about. I could really user this information as well. It makes it very difficult to do certain things.

System Specs: OS - Windows 7 Home Premium 64-bit SP1, CPU - AMD Phenom II X4 945, 3.0Ghz, RAM - 8Gb DDR3, GFX Card - 2048MB NVIDIA GeForce GT 640, FPSC-R Version - Beta 1.006
Auger
13
Years of Service
User Offline
Joined: 21st Aug 2011
Location: Out There
Posted: 31st May 2014 02:43 Edited at: 31st May 2014 06:10
yeah I think we'd need the angle of rotation of the player. Not sure if we can get that now.





[Edit]



okay been looking at this, and think this might be the formula



to the find angle between two 3d points in lua



For the two 3d points (x1,y1,z1) and (x2,y2,z2)



lua code



math.acos( (x1 * x2) + (y1 * y2) + (z1*z2) / (math.sqrt (x1 + y1) *math.sqrt(x2 + y2) * math.sqrt( z1 + z2))
Dralel
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 4th Nov 2013
Location: UK
Posted: 31st May 2014 09:01
Interesting, how would that line of code fit into my script?

GPU: GTX 660, CPU: i7 3770 Intel 3.40ghz x4, PSU: 650 Watt, RAM: 8GB DDR3, OS: Win7 Ultimate 64-bit
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 31st May 2014 14:34
Quote: "math.acos( (x1 * x2) + (y1 * y2) + (z1*z2) / (math.sqrt (x1 + y1) *math.sqrt(x2 + y2) * math.sqrt( z1 + z2)) "




missing an end bracket (i think) but regardless this gives me a result of -1.inf

keep going though, really want this to work!





for the questions yes you can change the text, there's a post about it somewhere but i never actually tried it myself



and no you can't freeze the game, you can set a delay to display a prompt for but that's about all.

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
Auger
13
Years of Service
User Offline
Joined: 21st Aug 2011
Location: Out There
Posted: 31st May 2014 20:00
Okay reworked the code this should work. I'll try it later but wife wants me to go work in garden



math.acos(((x1 * x2) + (y1 * y2) + (z1 * z2)) / (math.sqrt(x1 ^ 2 + y1 ^ 2 + z1 ^ 2) * math.sqrt(x2 ^ 2 + y2 ^ 2 + z2 ^ 2)) )
Dralel
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 4th Nov 2013
Location: UK
Posted: 31st May 2014 20:03
Quote: "you can set a delay to display a prompt for but that's about all."


I see, so how do I go about delaying the prompt for a longer duration?



Quote: "Okay reworked the code this should work. I'll try it later but wife wants me to go work in garden"


Nice, take your time, can't wait to test this out!

GPU: GTX 660, CPU: i7 3770 Intel 3.40ghz x4, PSU: 650 Watt, RAM: 8GB DDR3, OS: Win7 Ultimate 64-bit
PM
The Tall Man
10
Years of Service
User Offline
Joined: 24th May 2014
Location: Earth
Posted: 1st Jun 2014 01:09 Edited at: 1st Jun 2014 02:36
I just recently did some C++ code that finds the angle between a player and an object, for getting an imposter to always face the player. Yes you do need to know the player's rotation to see if they're facing that direction. But the direction itself is calculated by this. I'll translate into LUA:







Once you have the player's rotation angle also (from the apparently not-yet-available variable), subtract that from the EntityAngleY above (being sure to wrap the difference so it's between -PI and +PI. Then see if the absolute value of that angle difference exceeds a flexibility threshold (15 degrees for example). The higher the threshold, the more flexible (less picky) it will be about the player facing that object.



This ignores any difference in elevation though.



The problem with doing a division is that there will be a case where there's a divide by 0 error. Using math.atan2 eliminates that possibility.
PM
AuShadow
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 1st Jun 2014 11:00
You could sort the height problem a little by putting an if PlayerDist < 40 or something small so the player still has to be close, if entity is too high it will be out of the distance check

PC Specs: Windows 7 home 64-bit, Amd 7900 3gb DDR5 graphics, 8gb DDR3 Ram, Intel i7 3.4ghz

Feel free to visit and edit the public FPSCR resource wiki page: http://fpscrresource.wikispaces.com/home
BarZaTTacKS
10
Years of Service
User Offline
Joined: 3rd Feb 2014
Location:
Posted: 4th Jun 2014 18:12
How small can we go with that distance bracket? I noticed that when it is lower than default you cant get close enough to trigger.
PM
AuShadow
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 5th Jun 2014 06:04
I've had it as low as 50 but the item had to be on a table and near the edge , not sure where it measures the distance from, head mid-body or feet but I'm guessing its not feet

PC Specs: Windows 7 home 64-bit, Amd 7900 3gb DDR5 graphics, 8gb DDR3 Ram, Intel i7 3.4ghz

Feel free to visit and edit the public FPSCR resource wiki page: http://fpscrresource.wikispaces.com/home
BarZaTTacKS
10
Years of Service
User Offline
Joined: 3rd Feb 2014
Location:
Posted: 5th Jun 2014 15:23
@AuShadow I can confirm for sure its not the feet because crouching can trigger a lower number.
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 5th Jun 2014 19:50
it's the center of the object compared to the center of the screen

if you remove the Y axis you can get much closer/lower values but obviously this would only help if you are sure the object is going to be around the same height as the player (i.e. anything put upstairs in a house would still count as nearby even if you were on a different floor

still it can be useful in certain circumstances


life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11

Login to post a reply

Server time is: 2024-12-22 05:25:01
Your offset time is: 2024-12-22 05:25:01