im not able to drag the animator into the slot in the inspector
and im getting an error when i click on run bool in the inspector
"
UnassignedReferenceException: The variable anim of LeftRightPlatformPatrol has not been assigned.
You probably need to assign the anim variable of the LeftRightPlatformPatrol script in the inspector.
UnityEngine.Animation.Play (System.String animation)
but i definitely have an animator attached to the object and the name of the animation is correct, i just dont understand this.
As @PraetorBlue pointed out above, there are two things and they are VERY similarly-named:
Animator - an instance of a MecAnim core state machine object
Animation - a single Animation clip that does something.
Animations may be embedded into Animators, then you tell the Animator “Hey, change to walk state!” and it will do the right Animation, if set up correctly.
It is probably worthwhile going through a MecAnim tutorial. It’s super-powerful and could make life easier for you, especially once you get a lot of animations.
Technically it IS possible to use the Legacy animation system and just use Animations directly and purely, but there is a ton more work to keep track of, IMNSHO. Unity might even stop supporting it sometime…
Eh, don’t worry about it… I still sometimes say one when I mean the other. I try to think about the Animator as an “ator” in my head, so I will tend to call it “ator” instead of Animator in conversation.
I make up a lot of words actually, and sometimes some of them make sense. I think ator makes sense for Animator.
Hm, then I guess you could call an Animation a “shun…”
“Ey Warren, hook up the all the shuns to the ator, let’s go fly this spaceship!”
Precise professional technical terminology always.
Ha ha that actually makes a lot of sense. Hey Kurt im really battling with my NPC’s, trying to get him to patrol , put his arm out when the player gets close, down again when the player moves away, detect when the player is landed, move towards the player when hes close enough, i currently have a spaghetti bowl full of bools and if statements it seems really perplexing trying to get all this working with the animations etc, whats the best way to do this?
I feel your pain! Spaghetti is delicious but not so much in patrol AI code.
Knowing nothing more than you say above, here are my thoughts: You gotta break the problem down.
I see three distinct scripts with only a little bit of awareness of each other.
First of all, Animator states for your rescuee:
idle
idle waving
walking
Script 1 - patrolling the platform:
go to waypoints (set ator walking) in some kind of order
if no waypoints here (small platform), just idle
maybe stop at a waypoint for a few seconds (set ator idle)
periodically check for player landed
if see player landed, goto player (disable Script 2 below)
if player lifts off, return to walking, enable Script 2 below
Script 2 - beckon the player
periodically check distance to player for waving (ignore player landed status, just distance)
if less than this distance, set ator to idle waving
This script gets disabled by Script 1 above when the player lands
Script 3 - board the ship
IF:
the rescuee ever gets within a small range of the ship
the player ship IS landed
THEN:
turn off above scripts and tween into the ship
It’s easiest if this boarding cannot be interrupted / reversed: make the tween quick and even if the player lifts off, the tween succeeds from original point at start of this to arrival in ship
Alternately you can temporarily turn off player controls while rescuee is boarding
When the rescuee boards, destroy him and update your onboard count.
Final thoughts:
I’d put all three scripts on the rescuee and let them find each other, or else drag references into each other. Here is what they need to tell each other:
script 1 disables script 2 when going to ship
script 2 enables script 2 when ship out of reach
script 3 disables both script 1 and 2 when activated by close proximity
FINAL FINAL thoughts:
in the Update() of each of these I would have two sections, probably two separate functions:
Decide();
Enact();
Decide would set local boolean states on and off
Enact would just do the moving or set the ator bools, etc.
The really cool part about that last thing is you can implement a timer that only runs Decide once every random amount of time, like 0.5 to 2.0 seconds randomly.
That way if there are five rescuees waiting, they don’t all instantaneously lockstep start moving; it makes them seem like real agents.
I WANNA PLAY YOUR GAME! GO WARREN!
Also, I have this setup (pretty much) in my Impulse One game. I’ll make a video here and show you, or you can grab it off the appstore or google play… just search Kurt Dekker Impulse One.
Thats very interesting, i was wondering about loading and unloading particular scripts and wasnt sure if things were done that way…hey looking at your videos i am jealous!!!
you should really setup a youtube channel, though im sure you prob dont have time. thanks again mr Dekker!