You can use custom actions to find exact positions, but you can otherwise use Triggers. Triggers can be used to detect the presence of a specific object - you can have a bool that is True when the object enters the Trigger, and False when it leaves.
I know how to do this in script (find distance between two objects) and was using it in Unity scenes but I have tried to make an Actionlist that takes two GameObjects and returns the distance between them in a global variable. In this way I could have the typical NPC-detects-Player-depending-on-distance scene. I have followed your tut but the template does not have a return variable that can be used in AC.
I would be very willing to pay for such a thing, you see I am most interested in stealth scenes.
Yes, It could be easy but you must know that those scripts I mention I just copied from tutorials in Unity so I am still a neophyte in scripting . Please consider the following:
Essentially I want to have an AC ActionList with these parameters:
· Object 1 (GameObject) (normally this would be the Player)
· Object 2 (GameObject) (normally this would be the NPC)
· Minimum distance to detect (float) (I choose it as a parameter)
· Returns a global variable float with the distance (for future possible actions such as shooting or exploding, etc.)
Within this function if the distance < Min distance then Object1 follows Object2 as long as it is smaller
If this is written as clearly as your example Template in the tutorial I would be willing to pay max 50 € for it. Do you know of anyone willing to do it?
where the NPC (object1) follows the Player (Object2) as soon as the distance between the two is less than a predetermined value (externally defined). When this distance is greater then the NPC stops. I wanted also a returned bool variable that is set when the NPC has 'found' the Player (gotcha!) so I could use it to further create actions like explosions, etc.
If I were to get such an ActionList I could use it as a Template for me rather than the insipid Template about setting a Rigidbody (sorry) and I could do other stealth actions I have in mind.
Mind you, I have achieved the same thing with a Trigger as a child of the NPC which when the Player enters it it starts the NPC Follow Player action. Then I place Safe Areas (another trigger) around so that when the Player enters these areas it starts the NPC stop following Player action.
So my request above is mainly for my own instructional purposes and of course seeing the guts of that action would give me a lot of intellectual wealth.
I haven't read it myself, but I've seen people talking very highly about it recently, especially because it (apparently) explains the Unity scripting system in a very accessible way.
AC builds on Unity, and obviously has to follow the rules as laid down in the game engine itself, so it definitely makes things a lot easier if you get a firm grasp of Unity before trying to get AC to do things it doesn't handle out of the box.
Snebjorn: I know there are books galore to learn C# and Unity but I am very, very old and have no energy nor willingness to start learning a fresh new language (in my younger active life I was an active system programmer in C )
I don't want to develop a 'game' but just scenes with different scopes just for kicks, I have done the same with Unreal, Valve, Unity, WinMaker and now I like AC.
If I get to be able to change one or two functions (funny they call them now 'Methods") in AC to fit one or two 'situations' I'd be happy.
If you think what I offer (50€) is too little to make any junior fellow interested then please let me know what would you suggest.
No problem - I just thought I'd mention this book because I've heard it focuses on the Unity scripting system without trying to teach the basics of programming at the same time.
I've seen too many of those "Teach Yourself Professional Game Design, Systems Programming And Advanced Quantum Physics From Scratch In 30 Minutes Or Less" books. :-)
EDIT: Also: "Complete Idiot's Guide To Open Heart Surgery - A Hands On Approach"
But actually, there's some code in AC's NPC script that does something very close to what you're looking for: the StayAwayFromPlayer method. That's probably a good starting point - it would just be a matter of modifying the logic to detect the player and set him as the followTarget instead of moving away from him.
I really don't think this should be handled through action lists - the StayAwayFromPlayer method is called from the NPC's _Update method.
See the scripting guide for more on this function - this is the recommended source for help with script functions.
The "int _id" parameter refers to the Variable's ID number - which is shown just to the left of each variable's name in the Variables Manager: e.g. 1: Played intro has an ID of 1.
The Upload function is a part of the Variable's class (see this page). You can call it with the following:
AC.GlobalVariables.GetVariable (2).Upload ();
Where 2 is replaced by your variable's ID.
So the following would set the variable with ID = 2, to a new value of 5.5, and affect it's "Linked to" source as well:
THANKS. I made it work now my script detects the distance between the Player and the Enemy and shows in screen but just once !!
Object:My Enemy Attack
Dialog:Play speech-> [var:6]
I must be checking this distance constantly as I move the Player so that I can move the enemy towards the Player if less than a certain distance or stop him if not and this I can do with your standard ActionLists.
I have done it now!!. With AC actions after I get the Global Variable from my script I do a Variable:Check with 15 (my minimum distance) and if < I do a NPC Follow and if > I do a NPC stop following Action and from either one it lops back into my new Action to check the real distance. Of course I have to run this cutscene in Background mode otherwise it just gets clobbered.
Thank you for the Variable 'tutorial' I can use this for many of the special actions I wanted such as Spawning objects, Get/SetPosition of an object.. these are things that were possible in PlayMaker which will work well with my mainly Stealth type scenes.
Comments
AC.GlobalVariables.SetFloatValue (the_variable_id, the_new_value);
Essentially I want to have an AC ActionList with these
parameters:
Object 1 (GameObject) (normally this would be
the Player)
Object 2 (GameObject) (normally this would be
the NPC)
Minimum distance to detect (float) (I choose it as a
parameter)
Returns a global variable float with the
distance (for future possible actions such as shooting or exploding, etc.)
Within this function if the distance < Min distance then
Object1 follows Object2 as long as it is smaller
If this is written as clearly as your example Template in
the tutorial I would be willing to pay max 50 € for it. Do you know of anyone
willing to do it?
The "int _id" parameter refers to the Variable's ID number - which is shown just to the left of each variable's name in the Variables Manager: e.g. 1: Played intro has an ID of 1.
The Upload function is a part of the Variable's class (see this page). You can call it with the following:
AC.GlobalVariables.GetVariable (2).Upload ();
Where 2 is replaced by your variable's ID.
So the following would set the variable with ID = 2, to a new value of 5.5, and affect it's "Linked to" source as well:
AC.GlobalVariables.SetFloatValue (2, 5.5f);
AC.GlobalVariables.GetVariable (2).Upload ();