Offline documents and videos and notification on new documents,tutorials and videos

Did you know: Field of view for player or enemy

Did you know: Field of view for player or enemy

Postby SolarPortal » 23 Apr 2015, 12:38

Did you know that you can calculate the field of view of a player and check whether an enemy or player is in range in front of you.

Use this lua command in an update loop:

Code: Select all
direction = newType.vec3(entity.getDirection(entity.getIDFromTag("enemy"), obj));
forward = newType.vec3(entity.getForward(obj));
angle = vector3.angle(direction.x, direction.y, direction.z, forward.x, forward.y, forward.z );
sky.lprint("angle: "..angle);


Great for enemy visibility or player targeting etc..

Example image:

Image
Conceive, Quantify & Do!
Skyline Game Engine - Lead Developer.
Please provide as much information as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 3770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3082
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Did you know: Field of view for player or enemy

Postby ant0N » 23 Apr 2015, 16:23

Thank you! this is what I need. :D :D
Sorry for my English. :)
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 413
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: Did you know: Field of view for player or enemy

Postby SolarPortal » 23 Apr 2015, 16:24

lol cool :)
Conceive, Quantify & Do!
Skyline Game Engine - Lead Developer.
Please provide as much information as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 3770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3082
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Did you know: Field of view for player or enemy

Postby SolarPortal » 23 Apr 2015, 16:54

Updated with an image to make sense to non-scripters
Conceive, Quantify & Do!
Skyline Game Engine - Lead Developer.
Please provide as much information as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 3770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3082
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Did you know: Field of view for player or enemy

Postby TattieBoJangle » 23 Apr 2015, 17:05

Will this work With AI to save on performance with Pathfinding.
Case: CM Storm Trooper CPU: I7 5930k X99 Cooler: Noctua NH-D15 Graphics: Asus GTX 1080 Motherboard: Rampage Extreme V x99 Ram: RipJaws DDR4 3000mhz Storage: x2 SSD Crucial 500GB + x5 2TB Hdd PSU: Evga 1500w OS: Windows 10
User avatar
TattieBoJangle
Skyline Lead Moderator
Skyline Lead Moderator
 
Posts: 842
Joined: 26 Jan 2015, 00:15
Location: United Kingdom
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer
Skill: Great creative

Re: Did you know: Field of view for player or enemy

Postby SolarPortal » 23 Apr 2015, 17:45

yes, this can be used for enemy AI or other NPC's in the scene, not just the player. It is also not physics based, so there are many use cases for this snippet.

This could be used to chase the player if you wander into their sights or sneak up on them. But once they have sighted you, you need to use waypoint(spline paths) or navmesh(pathfinding) in order to follow the player around a complex environment, otherwise they end up running into a wall. The best way of saying is that it compliments a pathfinding solution(spline paths or navmesh).

Hope that makes sense :)
Conceive, Quantify & Do!
Skyline Game Engine - Lead Developer.
Please provide as much information as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 3770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3082
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer


Return to Documents, Tutorials and Videos

Who is online

Users browsing this forum: No registered users and 1 guest

cron