Product Chat / [SOLVED] Lua IntersectAll AI shoots through entities

Author
Message
SomeoneNew
5
Years of Service
User Offline
Joined: 2nd Jun 2019
Location:
Posted: 11th Jun 2019 23:44
Hey Guru's
IntersectAll what am I doing wrong ?

I have placed player on 1 side of an entity and AI on the other side.
And 1 is the AI and 2 is the target:
test12 = IntersectAll(x1,y1,z1,x2,y2,z2,obj)
PromptDuration("test12 "..test12,5000)
It returns 0 nomatter where I stand (infront of entity or besides entity).

The problem: the AI keeps shooting me through different entities (doors and others)
Thanks in advance

The author of this post has marked a post as an answer.

Go to answer
PM
Wolf
Forum Support
17
Years of Service
User Offline
Joined: 8th Nov 2007
Location: Luxemburg
Posted: 12th Jun 2019 00:07
You mention doors, does it only shoot you through dynamic (green) entities?
SomeoneNew
5
Years of Service
User Offline
Joined: 2nd Jun 2019
Location:
Posted: 12th Jun 2019 08:59
Hey Wolf
Both green and red, it seems to be the height, giving a double hight (3 times own height it feels) then it works
I guess I will try with some subtraction of some height to correspond to the player height.
Thanks
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 12th Jun 2019 18:45 Edited at: 12th Jun 2019 18:49
This post has been marked by the post author as the answer.
can you post your script or a clearer example, ray casting works fine for most objects (i think tiny objects can be missed but generally it works) it looks like you're using the position of the objects directly which is possibly the issue as this uses the origin point which is generally on the ground, your ray cast might be hitting the terrain or missing the collision shape of the object - especially true for characters? also hidden objects and objects with collision turned off do not return contacts

try this one and just change the 'name' of the entity running the script to the 'e' number you want to ray cast to.
(call it ray.lua)


lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 12th Jun 2019 19:25
Nice. But I'm a little confused. Can you please explain some of the
"name" functions or techniques? And in the video are you raycasting
from the player to the AI soldier?? If so, then I understand.
-- so the name "tonumber(name)" calls the name of the object and
makes it a number? but well, when is it best used, and how?

In other words, what if you didn't use the name part in that script,
would it still work then? I thought IntersectAll just give a 0 or 1...?
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 12th Jun 2019 20:09
IntersectAll returns the object Id of the first object the ray intersects (i.e. goes from 'outside' to 'inside').

The problems usually occur when the object doesn't have an 'inside', i.e. not enough thickness to it, or when two objects are touching or overlapping, which can confuse the code.
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 12th Jun 2019 20:29
Quote: "Nice. But I'm a little confused. Can you please explain some of the
"name" functions or techniques?"

init_name(e,name)
allows you to access the 'name' from the entity's properties panel in the editor via script - in the above script i store it as _name[e]

Quote: "-- so the name "tonumber(name)" calls the name of the object and
makes it a number? but well, when is it best used, and how?"

yes, i need the name to be a number as i want to store the entity number to get some info about it

Quote: "In other words, what if you didn't use the name part in that script, would it still work then? "

depends, you would need to tell the script which entity or position to end the ray cast at

Quote: "And in the video are you raycasting from the player to the AI soldier?? If so, then I understand."

yep, it would make more sense to do it in reverse if you were trying to simulate the AI firing etc but my example is merely to show contact reporting works fine

Quote: "I thought IntersectAll just give a 0 or 1...?"

no, the documentation is wrong, it returns 0 or the AI number (i.e. 7000) of the object hit
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: 13th Jun 2019 00:37
Ray casting basically works by firing an imaginary light ray through the 3d world and detecting where the ray intersects between 3d entities littering said world. It's effectiveness relies on the 3d entities themselves being 'well behaved', i.e. a single plane is not a 3d entity (which is a good thing, you don;t want to pick up particles or decals as 3d objects!) and overlapping 3d objects will tend to confuse things as well.

If you ray cast from within an entity the first 'intersect' detected will be the exit from said entity so the function has an ignore parameter to enable you to tell it to ignore that intersect and go on to the next object, this doesn work of the next intersect happens to be a separate entity which overlaps the 'ignore' entity, in this case the code just gets very confused!

Basically what I am saying is A) don't use ray casting where you have overlapping entities and B) don;t have entoties constisting of single planes (i.e. 0 'thickness') as walls!

Been there, done that, got all the T-Shirts!
PM
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 13th Jun 2019 03:15
IntersectAll returns the object Id so the object hit should be dynamic due static one return nil, and you'll get error.
I've noticed too than a mesh should be zeroed (0,0,0), so a mesh composed of several parts often has issues a leats you add some bone to it.
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
SomeoneNew
5
Years of Service
User Offline
Joined: 2nd Jun 2019
Location:
Posted: 13th Jun 2019 21:57
Hey all
Thanks
It turns out that my previous functions did pass high values on the Y front:
GetEntityPositionX(e),GetEntityPositionY(e)+240,GetEntityPositionZ(e),destx,desty+240,destz,AIObjNo
Which I did alter to much lower values.
Thanks smallg
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 26th Jun 2019 03:56

What if we wanted to return the name in text, example; "Concrete Bunker (3)"?
I tried just Prompt (name), and name[e] but so far no...


PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 26th Jun 2019 12:46
Change the name of the object in their properties panel then
Prompt (_name[e])
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Login to post a reply

Server time is: 2024-11-24 00:36:36
Your offset time is: 2024-11-24 00:36:36