NPC Movement

Creating scripts
User avatar
Geoff Quinnell
Posts: 43
Joined: Sun Jul 28, 2013 10:35 am
Has thanked: 17 times
Been thanked: 71 times

NPC Movement

Post by Geoff Quinnell »

Hi
I put this question in the OSgrid forum, but it's been a bit slow in replies....
so to repeat in here...

I am trying to get to grips with NPC's using the Ferd Frederix NPC Recorder.
So far it's working out ok, but can I ask?...
Is it true you can make NPC's attack nearby avatars?
If so, can I also make NPC's do the opposite... and avoid avatars... like a "run and hide" instruction?

Thanks for any help.
Geoff
User avatar
skindup truk
Posts: 46
Joined: Fri Aug 29, 2014 8:39 pm
Location: Australia
Has thanked: 7 times
Been thanked: 36 times
Contact:

Re: NPC Movement

Post by skindup truk »

Geoff Quinnell wrote:Hi
I put this question in the OSgrid forum, but it's been a bit slow in replies....
so to repeat in here...

I am trying to get to grips with NPC's using the Ferd Frederix NPC Recorder.
So far it's working out ok, but can I ask?...
Is it true you can make NPC's attack nearby avatars?
If so, can I also make NPC's do the opposite... and avoid avatars... like a "run and hide" instruction?

Thanks for any help.
Geoff
the answer i like to give as a part time sw eng and beginner scripter for kitely / opensim is that "anything is possible" ;) this idea is very similar to what i wanted to try learning next... maybe you can help me get started with some links from your research so far...? catch you around :)
User avatar
Geoff Quinnell
Posts: 43
Joined: Sun Jul 28, 2013 10:35 am
Has thanked: 17 times
Been thanked: 71 times

Re: NPC Movement

Post by Geoff Quinnell »

Hi
Thanks for your reply and yeah sure, you are welcome to my limited info/links so far
I used the following link...
http://www.outworldz.com/Opensim/posts/NPC/default.htm
That has allowed me to set up a simple and basic NPC that appears and walks round a bit, tp's to another spot, and walks round again... then tp's back... told you it was basic lol
There are a lot of other things you can set up with this system, but the thing I wanted to add was the "run and hide" instruction, so that the NPC moves to a set, hidden spot if a (normal) avatar appears nearby.
So far no luck, but anyway that's my link... hope it works for you.
Geoff
User avatar
skindup truk
Posts: 46
Joined: Fri Aug 29, 2014 8:39 pm
Location: Australia
Has thanked: 7 times
Been thanked: 36 times
Contact:

Re: NPC Movement

Post by skindup truk »

thanks for the link :)

i just found this Linden Script Language slideshow somewhere like the "learning center" in Kitely world (graham mills world i think) with 25+ posters... one of them said script can scan and detect any nearby avatars... based on that event (or depending on whether they are walking / flying / running / possess some name / say the password / any other event desired, then yeah it should be possible to then script the NPC entity to follow a path / teleport to hide etc...

PS. i just glanced at the LSL info here http://wiki.secondlife.com/wiki/LSL_Library lots of example snippets and the list of functions and events (aka states) looks pretty good... by far the coolest thing is the "prim message service" which allows the scripted prims to send data between themselves... that could lead to some really cool emergent behaviours eg. flocking / ad hoc swarming / scattering and regrouping etc :P
User avatar
Geoff Quinnell
Posts: 43
Joined: Sun Jul 28, 2013 10:35 am
Has thanked: 17 times
Been thanked: 71 times

Re: NPC Movement

Post by Geoff Quinnell »

Hi again...
Some good possibilities... although I have to say... with my limited skills, I have ideas that frustratingly remain just ideas.
If I discover any other "options" I'll let you know.
Geoff
Graham Mills
Posts: 1314
Joined: Sun Dec 23, 2012 2:26 pm
Has thanked: 1134 times
Been thanked: 1141 times

Re: NPC Movement

Post by Graham Mills »

I'm guessing this could be done with varying degrees of sophistication using the OpenSimWorld NPC toolkit (and doubtless others). There isn't any direct support for avoidance AI though presumably this could be added provided it wasn't too computationally intensive. With the proviso that I haven't actually tried it ;) ...

It might be faked to some extent, however, if the NPC is rezzed in a clearing with a limited number of access (or departure) routes, each covered with a particular collision mat. You can communicate with the NPC (called Fred here) on channel 68 so an avatar stepping on a particular collision mat initiates an NPC's movement towards a specific (and more distant) waypoint by giving a command on channel 68:

Code: Select all

default
{
  collision_start(integer n)
  {
    llWhisper(68, "! 0000 UUUU Fred go to Escape1");
  }
}
where Escape1 is a waypoint where a further command sequence could be executed from a notecard. Such sequences include conditional branching based on a probability so a degree of randomness is possible thereafter. Other access routes to the clearing would have mats with a similar script but specifying a different waypoint. You can also use vectors in place of waypoints (which I have barely used), e.g.

Code: Select all

llWhisper(68, "! 0000 UUUU Fred runtovr <23,24,25>  <33,34,25>")
sees Fred run to a random location between those two points.

Of course, this doesn't get round the issue of having more than one avatar present in which case a more sophisticated approach would be required.

PS: If you want the NPC to "hide", you could change its clothing to a transparent set, e.g. by executing

Code: Select all

Fred dress transparent
where transparent is an appearance notecard "APP_fred_transparent".
These users thanked the author Graham Mills for the post:
Ilan Tochner
User avatar
Geoff Quinnell
Posts: 43
Joined: Sun Jul 28, 2013 10:35 am
Has thanked: 17 times
Been thanked: 71 times

Re: NPC Movement

Post by Geoff Quinnell »

Thanks Graham...
Sounds interesting, though as you know through our conversation in-world... I am no expert on scripting... so when I see you next maybe we can chat about this.
Cheers
Geoff
Graham Mills
Posts: 1314
Joined: Sun Dec 23, 2012 2:26 pm
Has thanked: 1134 times
Been thanked: 1141 times

Re: NPC Movement

Post by Graham Mills »

Of course, the collision mat script could determine what the optimum response would be based on the current position of all avatars and chat the appropriate command to the NPC. Doh!

I'll get some basic proof-of-concept working, Geoff, and get back to you (and here).
Graham Mills
Posts: 1314
Joined: Sun Dec 23, 2012 2:26 pm
Has thanked: 1134 times
Been thanked: 1141 times

Re: NPC Movement

Post by Graham Mills »

That sort of works (it should do, it's simple enough).

Observations:

1. The NPC's walk animation sometimes gets lost and it just glides. Not sure if you could play a walk animation while moving it.
2. You can use osNpcRemove to get rid of ("hide") the NPC but it doesn't sync with the controller by default.
3. The NPC doesn't run as fast as an avatar so you need to place your collision mat a good distance from the NPC (30 m minimum) -- think avenues of hedges, bushes, trees -- or be prepared to use teleporting for the NPC after an initial run. Alternatively, you could use osSetSpeed to slow down the avatar selectively as if it was wading through water or snow.

I still haven't played with wayfinding.
User avatar
Geoff Quinnell
Posts: 43
Joined: Sun Jul 28, 2013 10:35 am
Has thanked: 17 times
Been thanked: 71 times

Re: NPC Movement

Post by Geoff Quinnell »

Thanks Graham
Not been at PC tonight, so just seen your post... When we both get a chance I'll show what I have set up so far, and the idea/effect I had in mind... and thanks again for all your help and suggestions.
Speak soon
Geoff
Post Reply