Jump to content

Pick() how to use it ?


YouGroove
 Share

Recommended Posts

Hi,

i use Pick , but i don't understand why it don't work , or only few times ?

 

I put a test map and scripts if someone have time to make the test :

 

How to test :

Put Pick.map on your "map" folder

Put the two scripts in your folder "Scripts/Objects" directly

 

Run the game, move the character near the mob, and you'll see the player is not visible even on the line of sight of the mob many times.

PICK.zip

Stop toying and make games

Link to comment
Share on other sites

Hmm, just tried and he started moving towards me. I also think I know why you are getting crazy AI movement. You need to play around more with some of the values to the nav functions. Use a higher acceleration value than 1 (3rd param to GoToPoint()). Very low ones make a rubberbanding effect like you are seeing in your other post. Try 10, or 100 even to remove that effect.

Link to comment
Share on other sites

I didn't examine your code much but to me it looked like when the player was looking at the enemy the enemy would move, but if I would look away then the enemy would stay still. But if I'd turn the player just slightly then the enemy would come at me again. This for sure has something to do with your code and not an LE issue. You just have to work it out man. Welcome to programming where it's not about creating things it's about fixing issues. That's really what programming is and in the process of fixing issues you end up making something wink.png

 

I think this is why some people don't like it. If you don't enjoy constant problem solving and fixing things then you won't last long enough to get to a point where you can just make something work without too much trouble. That takes experience though and you have to last that long and not give up out of frustration of constantly fixing of things smile.png

Link to comment
Share on other sites

I just expect a ray pick from A to B, when A is on line of sight to say : "VISIBLE"

Perhaps some more easy to use pick() function would help, i like easy systems.

 

 

How to test :

Put the map on your map folder

put the scripts on the forlder "Scripts/objects"

Run the game, and turn your player to be back to the mob to see player visible appear.

 

That's strange, Pick() is taking the two spheres positions to raycast, it should say ok each time these spheres are in line of sight ?

debug.zip

Stop toying and make games

Link to comment
Share on other sites

Can pick() only find entity when the two entities are facing each other ?

 

Of course not. You are making a line between 2 points and anything it hits (given collision type I guess) will be registered. Make sure you aren't hitting the character itself if you are using it's position since it's position will be "inside" itself and would hit itself. Put some debugging in. Are you hitting anything? If so print it's name out and find out what.

  • Upvote 1
Link to comment
Share on other sites

Make sure you aren't hitting the character itself if you are using it's position since it's position will be "inside" itself and would hit itself

self.entity:SetPickMode(0) is preventing that problem.

 

It displays "Player visible" , only when the player is facing in a direction backwards ?

 

 


function Script:RaycastPlayer2()


self.entity:SetPickMode(0)

self.debugSphere:SetPickMode(0)
self.debugSphere3:SetPickMode(0)


local posPlayer = self.target:GetPosition()
local posMob = self.entity:GetPosition()

posPlayer.y = posPlayer.y +1
posMob.y = posMob.y +1

self.debugSphere:SetPosition( posPlayer, true)
self.debugSphere3:SetPosition( posMob, true)
-- disable model picking


local world = World:GetCurrent()
local pico = PickInfo()


world:Pick(posPlayer, posMob, pico, 0, true , Collision.Character)

if pico.entity == nil then
self.playerVisible = "nothing"
end

if pico.entity ~= nil and pico.entity ~= self.target then
self.playerVisible = "collision something"
end

if pico.entity ~= nil and pico.entity.script~= nil and pico.entity.script.teamid ~= nil and pico.entity.script.teamid == 1 then
self.playerVisible = "collision player"
end



end

Stop toying and make games

Link to comment
Share on other sites

Do you move your pick up Y value a little (since positions will be at the feet vs say midway up or even at eye level)?

Yes the two points are above floor, and the two spheres allows me to view the poinst in 3D space, and they are correct

 

 

posPlayer.y = posPlayer.y +1

posMob.y = posMob.y +1

 

self.debugSphere:SetPosition( posPlayer, true)

self.debugSphere3:SetPosition( posMob, true)

 

 

 

 

 

Are you getting any entity with the pick?

Main of the time i have this one responding, even when the two spheres are in their line of sight each to other one :

 

 

if pico.entity ~= nil and pico.entity ~= self.target then

self.playerVisible = "collision something"

end

 

 

When i rotate the player to be backwards the mob in it's direction i have this one responding

 

 

if pico.entity ~= nil and pico.entity.script~= nil and pico.entity.script.teamid ~= nil and pico.entity.script.teamid == 1 then

self.playerVisible = "collision player"

end

 

 

So direction is impacting the result whatever the two spheres are in the line of sight one of each other.

Stop toying and make games

Link to comment
Share on other sites

I increased the rayPick to 5

 world:Pick(posPlayer, posMob, pico, 5, true , Collision.Character) 

 

Now it detects player even throught walls , and rotating the player sometimes it detects sometimes not.

 

Who has a complete working Pick example between character and player ?

Stop toying and make games

Link to comment
Share on other sites

10 minutes to got it working in Unity, while i'm battling from some days in LE3 blink.png

unity.jpg

 

The code is as easy and clear and it works fine without any really strange problems like i have in LE3.

 


GameObject taggedObject = GameObject.FindWithTag("Player");

if (taggedObject != null)
{
t = taggedObject.transform;


rayDirection = t.position - transform.position;

if (Physics.Raycast(transform.position, rayDirection, out hit, 100.0f)) {

Debug.DrawLine(transform.position, hit.point,Color.blue);
}
} 

 

Well, i just come to reality and lower somewhat my LE3 expectations to avoid disappointements laugh.png

Stop toying and make games

Link to comment
Share on other sites

I have some simple pick code I will try to dig out tomorrow.

 

Scenario, I had a friendly tank driving about that when it got it in line of sight, an enemy tank would turn and fire to cause damage. The friendly tank could go behind a wall so it could not be seen and the enemy tank would stop firing. Then when the friendly tank came into view again at the other end of the wall, the enemy tank would turn and fire again.

 

Sometimes its a case of starting a fresh project just with your problem and starting the code from scratch. I did this because the enemy tank kept firing through the wall. Sorted it though. Also take a break for a bit, watch a film sleep on it.

Elite Cobra Squad

Link to comment
Share on other sites

trying to understand YouGrooves code. I think he talks a different language than me. :)

 

one thing i noticed already is that you start the picking from the wrong direction.

Your picking code is called from your Dog. But the picking starts from the player.

 

Will try to dig through it a bit more.

Link to comment
Share on other sites

I have some simple pick code I will try to dig out tomorrow.

No need, i will just go lot more slowly on LE3 project now, reducing my super pressure on this project laugh.png

 

 

Sometimes its a case of starting a fresh project just with your problem and starting the code from scratch. I did this because the enemy tank kept firing through the wall. Sorted it though. Also take a break for a bit, watch a film sleep on it.

I needed and wanted to have some basic AI work ready , working and done, the problem is good AI uses Raycast for many things.

I just spend so much time on that Pick() function and it looks like a simple to use function but not so trivial at final, this is very frustrating, while it was 10 minutes in Unity to code it from scratch reading docs.

 

I conclude with LE3 pick :

- the doc is not so good

- there is no generic exemples usable in any situations

 

 

Your picking code is called from your Dog. But the picking starts from the player.

I just need Pick() to detect the player between two points ( pick start point and end point) . Raycast in LE3 works between two points , it's not based on start point,direction and length like Unity.

 

If you have time, download it, change the mob script and make it able to detect player when the player is on the line of sight without any obstacle (whatever is the orientation or player and mob).

Stop toying and make games

Link to comment
Share on other sites

I think beo6 is right. It's mob AI so you should pick from mob to player.

 

if (world:Pick(posMob+Vec3(0,1.2,0), posPlayer+Vec3(0,1.6,0), pi, 0, true)) == false then

return 0

end

 

-- did we hit our target?

if pi.entity == self.entity then

return 1

end

---

Scott

 

Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060

Link to comment
Share on other sites

That's really but really weird function then.

Why the first point must be the same as the entity calling Pick() ? This is nowhere in the docs.

I thaught it was a really general Raycast function that just needs two 3D points and detects anything between these points (like Unity and others can do).

 

 

I tested changing the order

 

world:Pick(posMob, posPlayer , pico, 5, true , Collision.Character) 

 

But it don't work better laugh.png

 

I don't think there is a simplest way to code raycast ?

 

world:Pick(posMob, posPlayer , pico, 5, true, Collision.Character) 

if pico.entity == nil then 
self.playerVisible = "nothing" 
end 

if pico.entity ~= nil and pico.entity ~= self.target   then 
self.playerVisible = "collision something"
end

if pico.entity ~= nil and pico.entity.script~= nil and  pico.entity.script.teamid ~= nil and pico.entity.script.teamid == 1   then 
self.playerVisible = "collision player"
end

Stop toying and make games

Link to comment
Share on other sites

if (world:Pick(posMob, posPlayer,pi, 0, true)) == false then --pick the correct way.
 return 0
else
 self.debugSphere3:SetPosition(pi.position) -- set debg sphere where pick was sucessfully hit.
 local n = pi.entity:GetKeyValue("name","no name?")
 System:Print(n) --print name of picked item
end

 

Also if you print out the pick name you can see Bip HEAD alot that means the mob is picking itself in the head.

So maybe pick from infront of the mob or above. or use setpickmode(0) recursive.

 

EDIT: added my small trial.

DogAI.zip

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

I call setpickmode(0) before on the dog script , it could not pick himself or am i wrong.

(The crawler have only Physic character collision)

 

I tried your script, and if i turn around the mob it finish to don't detect the player , even when i stop moving it needs some time before detecting the player.

 

There is something weird with pick it seems.

picky.jpg

 

You have same code as me with two 3D points to call Pick():

 

if (world:Pick(posMob, posPlayer,pi, .0, true)) == false then ... 

 

So the crawler should detect the player when there is no obstacle between them every time.

Why does it not works like above example ?

Stop toying and make games

Link to comment
Share on other sites

About the wrong direction of the pick. That was only the logic i use. If i wan´t a dog "seeing" things through pick i have the pick start from the dog. It was just a hint.

 

And this is definetly a bug or i am doing something horribly wrong.

 

it looks like it has something to do with the Character controller. as soon as the character controller is used it does not register a collision.

If i parent another entity to the character controller that parent gets hit no problem. The same is with shadmars script.

Link to comment
Share on other sites

watch aggror's tutorial on the turret you have to make a box for the character for pick to find the player easier, as with out the box it can't hit the player.

Are you kidding ? I have declared a character controller, why should i use a a trick and do more work ?

Is not character controller a physic object with collision already, that pick should always detect it in any case , like Unity raycast and character physic capsule volumes.

 

There is a bug with Pick , the raycast should detect the character controller physic cylinder between two 3D points at any time (without adding any physic shapes or any tricks).

Or its not a real raycast function.

 

But thanks for the suggestion smile.png

Stop toying and make games

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...