Scripts / Light Follow Entity Script

Author
Message
bluemeenie195
6
Years of Service
User Offline
Joined: 28th Oct 2018
Location:
Posted: 28th Dec 2019 19:48
Cool Script that attaches a light to a moving entity.

https://steamcommunity.com/app/266310/discussions/0/1651044588037470142/

PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 28th Dec 2019 21:15
i like the electric style attack, shame there's an explosion effect though
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
bluemeenie195
6
Years of Service
User Offline
Joined: 28th Oct 2018
Location:
Posted: 29th Dec 2019 11:37
Thanks smallg,

Didn't know if you checked out the script ? Unfortunately the script only allows one light and one entity.

I've been trying different ways to add more lights to the entity and in turn tried to fix the script to let use it on more than one entity per map, but couldn't get either to work.

Attachments

Login to view attachments
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 29th Dec 2019 18:23 Edited at: 29th Dec 2019 18:24
sure, make it an array/list and give it some way to get the id's
for me i just set
attachLightToMe[e] = e
in the character's init(e) part of the script (might want to add attachLightToMe = {} in the character script too just in case you want to use the script without any attaching lights in the scene - just so it won't cause any errors)
i.e.

then you can place the lights next to the entity you wish to attach it to (give the light the attached script) and done
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Attachments

Login to view attachments
bluemeenie195
6
Years of Service
User Offline
Joined: 28th Oct 2018
Location:
Posted: 29th Dec 2019 21:53
So I just got a chance to try your script upgrade and all I can say is WOW!

It works perfectly on multiple moving entities, and I was adding 3 to 4 lights per entity.

Really awesome Thank you !

Everybody should check out this script.
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 30th Dec 2019 12:09 Edited at: 30th Dec 2019 12:18

made a change to allow you to offset the lights pos / angle a bit so it should work better with multiple lights (i.e. they won't sit on top of each other now) and allows it to work with spot lights
but there seems to be a slight problem with the rotation... i'm not sure what is wrong but if you watch the red light especially his light changes x (if it was euler) angle very dramatically depending on which direction he is heading... but the angles all report being in the vector range (which is shown in the prompt) so i'm not sure why.

the script should basically just do the same as before - i.e. follow the entity and update the light rotation based on the entity angle - the only difference is there is supposed to be an allowance for a starting offset so the light doesn't necessarily have to be facing directly the same direction as the entity
it seems to work fine if there's no Y (euler) angle offset so i'm guessing there's some conversion weirdness happening

*note the red light is offset on the Y axis in the editor*
hopefully amen can jump in and tell me what i'm doing wrong here
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Attachments

Login to view attachments
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 30th Dec 2019 17:56 Edited at: 30th Dec 2019 19:44
Two bits look a bit dodgy. firstly once you have attached a light to an entity you probably want to stop the same entity from having another light assigned:


Secondly where you work out the angle offsets you probably should make sure they are within Euler limits, i.e. with a WrapAngle or bit of math.

Also where you position the light relative to the entity shouldn't you be rotating the offsets?


-- edited to add --
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 30th Dec 2019 19:57
Quote: "Two bits look a bit dodgy. firstly once you have attached a light to an entity you probably want to stop the same entity from having another light assigned:"

it should be fine right? if i wanted say a police car effect or dual flashlight effect you would want 2 lights... i can imagine cases with more and using an array/list i see no reason why it would cause an issue

Quote: "Secondly where you work out the angle offsets you probably should make sure they are within Euler limits, i.e. with a WrapAngle or bit of math."

hmm that might be the issue, i would have guessed since the result gets converted to radians and then to a vector it should be fine but hadn't actually considered that properly, nice spot

Quote: "Also where you position the light relative to the entity shouldn't you be rotating the offsets?"

yes i should be, missed that but it wouldn't cause the issue in the video... just means the lights would be in the wrong location, not the wrong angle.

it looks like all your lights in the video are facing the same Y as the characters by default? i'll check your suggestions / script tomorrow and adjust as needed if there's still an issue with the Y offset, thanks
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 30th Dec 2019 20:10 Edited at: 30th Dec 2019 20:11
If you want more than one light per entity your will need some way of telling the script to stop assigning them when you reach that number. Or you could use the entity name as a way of making sure the correct light is attached to the correct entities, like my light_control and sound_control scripts, you could also use that method to 'command' the behaviour of the lights (e.g. for the police car example have a 'Rotate' command).

Attached light_control script so you see what I mean.
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 30th Dec 2019 20:12
Ahh, I've just twigged what the issue may be!

You can't just add Euler angles together, you'll probably need to use quaternions!
Been there, done that, got all the T-Shirts!
PM
bluemeenie195
6
Years of Service
User Offline
Joined: 28th Oct 2018
Location:
Posted: 30th Dec 2019 20:37
I'm Loving where this script is heading !

[video=youtube]v=Gh-s3-5xLmA[/video]
PM
bluemeenie195
6
Years of Service
User Offline
Joined: 28th Oct 2018
Location:
Posted: 30th Dec 2019 20:42


Lets try that again.

https://www.youtube.com/watch?v=Gh-s3-5xLmA
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 30th Dec 2019 22:37
Quote: "If you want more than one light per entity your will need some way of telling the script to stop assigning them when you reach that number."

it already works with a max range though, i think yours just changed because you set it to math.huge so it picks up every light.... though yes having a specific way to assign them (probably by name) would be better i think a range is fine for most cases and quick testing

Quote: "You can't just add Euler angles together"

yeah thought that was what you meant with the second point before? should be able to just wrap them in a 1~360 check and it will be ok

Quote: "I'm Loving where this script is heading !
"

indeed, i'll add some script functions for the light to rotate (i.e. spin like a siren) or do a search light pattern too so you can have a real police helicopter looking for criminals
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 30th Dec 2019 22:47
The wrapping issue is one problem but the other more basic issue is that you can't just add Euler angles together unless you limit everything to one axis only, i.e. if you force x & z angles to be 0 then you can just add the y angles (assuming you take account of the wrapping properly) but if either of the other angles become involved things will not go the way you expect them to!

Probably much better to use quaternions from the outset then you avoid strange behaviour later on.

Been there, done that, got all the T-Shirts!
PM
bluemeenie195
6
Years of Service
User Offline
Joined: 28th Oct 2018
Location:
Posted: 30th Dec 2019 23:42
That would be awesome smallg. Even a flicker or flashing setting would be perfect.
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 31st Dec 2019 12:40 Edited at: 31st Dec 2019 12:43
Quote: "Probably much better to use quaternions from the outset then you avoid strange behaviour later on."

ok so i got close but it's not quite working... can't figure out what i'm doing wrong, only appears to show the light in certain directions and i would expect only the Y euler value to change but it changes all 3... (i know the euler aren't wrapped at the end but it's only for prompt purposes, they're not actually used - only the quat values are

lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
PCS
8
Years of Service
User Offline
Joined: 7th Jul 2016
Playing:
Posted: 31st Dec 2019 12:46
@bluemeenie195, that chopper with lights is awesome, what script did you use to add more than one light to the chopper, i tried but can get only one light to follow the chopper,
Windows 7 Professional 64-bit
Intel(R) Pentium(R) CPU G3260 @ 3.30GHz (2 CPUs), ~3.3GHz RAM 16GB NVIDIA GeForce GT 730
DirectX Version: DirectX 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 31st Dec 2019 13:40
You don't Add quaternions, in fact I'm not even sure why there is an Add function as I've never found a use for it.

Attached is my attempt at this, haven't quite ironed out a few issues with it yet though.
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 31st Dec 2019 14:34
One of the weird issues I'm having is that the AI seem to catch up with the light then it jumps away from them, as if the AI position is not being updated every frame. I'm going to have to add some debug to figure out what is going on there.

Rotation is tricky as you want to rotate the light around the Y axis of the attachment entity whilst also keeping the offset position relative to it and the light rotated in x & z relative to the attachment entity rotation. Will take me a while to sort out the math for that, probably best I do that before the drinking starts this evening.
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 31st Dec 2019 16:14 Edited at: 31st Dec 2019 19:18
ok probably final version from me - i really should be working on my own project instead of spending all my time playing with this :p

to use; name the lights "spin" / "search" / "fade" to activate the different effect or just leave the name normal to have it simply not have an effect (i.e. just follow the char) - can fine tune the effects in the script as needed
if you want the lights to spin or search on a different axis there is support for that in the script too


edit: should fix offset for lights without special effect
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Attachments

Login to view attachments
bluemeenie195
6
Years of Service
User Offline
Joined: 28th Oct 2018
Location:
Posted: 31st Dec 2019 17:38
Thank you so much smallg, and AmenMoses for all your help.

This is a game changing script now, were every moving entity has it's own personal light show.


PM
bluemeenie195
6
Years of Service
User Offline
Joined: 28th Oct 2018
Location:
Posted: 31st Dec 2019 17:42
Hi PCS,

It's just the updated light_npc script that smallg, and AmenMoses been working on.

You can add a bunch of lights now.
PM
Pink Panther
14
Years of Service
User Offline
Joined: 1st Feb 2010
Location:
Posted: 31st Dec 2019 18:58
What a great script! Thank you!
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 31st Dec 2019 19:16 Edited at: 31st Dec 2019 19:17
i realised my last version may not been working correctly with lights without any effect but with an offset to position (looks like it would have ignored the offset and placed the light at the parent entity) so i edited a new version (untested but should be fine) - script can be found in the last post.

Quote: "What a great script! Thank you!"

Quote: "This is a game changing script now, were every moving entity has it's own personal light show."

thanks, it was a fun one, hope it's useful or at least entertaining
still not working 100% but does a good enough job, maybe after amen cures his hangover in the next few days he'll show us how it's done properly
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
PCS
8
Years of Service
User Offline
Joined: 7th Jul 2016
Playing:
Posted: 31st Dec 2019 23:17
Ok testing lights on Bod's red pickup truck


Sorry for bad video quality
Windows 7 Professional 64-bit
Intel(R) Pentium(R) CPU G3260 @ 3.30GHz (2 CPUs), ~3.3GHz RAM 16GB NVIDIA GeForce GT 730
DirectX Version: DirectX 11
bluemeenie195
6
Years of Service
User Offline
Joined: 28th Oct 2018
Location:
Posted: 31st Dec 2019 23:41
That looks great !

I like the truck driving script too.
PM
PCS
8
Years of Service
User Offline
Joined: 7th Jul 2016
Playing:
Posted: 1st Jan 2020 00:00
bluemeenie195, thanks , the truck driving script is actually AmenMoses Helicopter script that i have modified to work on the ground. , All credit to AmenMoses.
Windows 7 Professional 64-bit
Intel(R) Pentium(R) CPU G3260 @ 3.30GHz (2 CPUs), ~3.3GHz RAM 16GB NVIDIA GeForce GT 730
DirectX Version: DirectX 11
Pirate Myke
Forum Support
14
Years of Service
User Offline
Joined: 31st May 2010
Location: El Dorado, California
Posted: 1st Jan 2020 04:50
All this is looking fantastic. Thank you all.
RIP
Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz, 2400 Mhz, 4 Core(s), 4 Logical Processor(s), 8gb RAM, Nvidia gtx660, Windows 7 Pro 64bit, Screen resolution 1680 x 1050.

New:
Intel(R) Core(TM) i5-8400 CPU @ 2.81GHz, 12GB RAM, Nvidia gtx1050ti 4gb, Windows 10 Home 64bit, Screen resolution 1920 x 1080. System Passmark 3774




GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 1st Jan 2020 17:08
Radical!
Now just need some tutoring on Amen Moses' quat or physics library...
so as to move objects forward in more than 'Y'; also 'X' rotation to get
vertical 'altitude' turns, like a proper 360 up and down. I think that
'Z' is a 'barrel roll' if I'm not mistaken. Any pointers?
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 1st Jan 2020 22:33 Edited at: 1st Jan 2020 22:40
correct so iirc you use something like

note; you'll want to wrap the angles and if you try to rotate in multiple axis at once it'll get messy (as we mentioned earlier in the post) but should work fine for a basic flight system
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
bluemeenie195
6
Years of Service
User Offline
Joined: 28th Oct 2018
Location:
Posted: 1st Jan 2020 23:07
Here's a version that will add a flashing light to a moving entity.

Attachments

Login to view attachments
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 2nd Jan 2020 05:49
Thanks smallg,
I tried many variations of that code, and for some reason, I am not getting
anywhere, except for a slow, steady rise and forward floating-- no rotation
or circular movement.

I added SetRotation; SetRotation(e, ox,y,z)
RotateX; RotateX(e, ox) and quite a few other things... beyond the original.
My head isn't getting better!
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 2nd Jan 2020 10:48
Quote: "Here's a version that will add a flashing light to a moving entity"

My version already has a flash, use the fade effect

For rotation you set the SetRotation to the angles you passed in to the rotate3d function before they were radians i.e

lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
bluemeenie195
6
Years of Service
User Offline
Joined: 28th Oct 2018
Location:
Posted: 2nd Jan 2020 12:13
Thanks smallg , I'll give the fade effect a try.
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 3rd Jan 2020 01:11
Yes!
PM
Teabone
Forum Support
18
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 25th Sep 2024 05:12
Does this script still work?
Store Assets - Store Link
Free GGC Resource - Resource Link

i7 -2600 CPU @ 3.40GHz - Windows 7 - 8GB RAM - Nivida GeForce GTX 960
bumblepuppy
2
Years of Service
User Offline
Joined: 13th Apr 2022
Location: Another Dimension
Posted: 3rd Nov 2024 20:53 Edited at: 3rd Nov 2024 20:57




Yep, worked for me (can't remember if I changed the script at all, but think it worked as posted)!

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-12-21 15:40:05
Your offset time is: 2024-12-21 15:40:05