How do I change the state of the AiActor?
by Will O-Reagan · in Torque X Platformer Kit · 05/24/2010 (5:47 pm) · 5 replies
I'm using the an AIActor and AIcomponent (extends dragon actor component) for a networked player. Right now, every tick I'm posting the position of the networked player, and the state, however, this has some bad results. For one, it plays the new state "Sound" every tick, and two, the animation only plays one frame, so I'm assuming this where I alter the source code to make the state not change when the state is already set to what the new state is right? But I'm getting kind of lost. I tried this code here...
But that literally did nothing, same exact behavior as before. So what do i do?
Not setting the state but only the position of the AI actor gives some animation and some sound, but not alot..
Is it possible I need to do another step to advance the state of the FSM like its getting locked in one state because i didn't initialize it?
public void SetState(IFSMObject obj, FSMState state)
{
if (state != null)
if (state.StateName.Equals(obj.CurrentState.StateName))
return;But that literally did nothing, same exact behavior as before. So what do i do?
Not setting the state but only the position of the AI actor gives some animation and some sound, but not alot..
Is it possible I need to do another step to advance the state of the FSM like its getting locked in one state because i didn't initialize it?
About the author
I have a degree in dramatic art, and literature, from UC Santa Barbara. I've worked for a few studios, also at Animax Ent in 2008, and some smaller studios. Currently studying Computer Science at CSU Channel Islands.
#2
Calling a set function is usually more costly than just checking first if the current value is acceptable. If your state doesn't change often, or even your position, you might want to consider a simple comparison check before setting them.
05/25/2010 (9:43 am)
Or you could check the current state before changing it?Calling a set function is usually more costly than just checking first if the current value is acceptable. If your state doesn't change often, or even your position, you might want to consider a simple comparison check before setting them.
#3
05/25/2010 (1:21 pm)
I'm not sure that would have made a difference.... Notice the solution didn't entail changing the state manually.
#4
for a standard tick/frame, you'll end up with
7 bools set + 2 float
vs
1 int comparison and 2 float set
While it may not be what will slow down your application to a crawl, checking first may allow you to speed up a lot your app, even slim it down a bit, and if you're gonna play in the multiplayer world, that's something good. Just a head's up ;)
05/25/2010 (2:29 pm)
I know, but it entails a lot of attribution.for a standard tick/frame, you'll end up with
7 bools set + 2 float
vs
1 int comparison and 2 float set
While it may not be what will slow down your application to a crawl, checking first may allow you to speed up a lot your app, even slim it down a bit, and if you're gonna play in the multiplayer world, that's something good. Just a head's up ;)
#5
But.. it's controlled by a player! So yeah, he's constantly moving and jumping around. It looks really awesome. What struck me as odd was I was immediately confused which controller was controlling which actor.. because they are indistinguishable when I used that update code.
05/25/2010 (3:18 pm)
This is a networked player, so he's constantly moving.. I only said it was an AI for simplicity's sake. Actually my networked player is derived from the AI class anyways, so it's not really a fib, in fact, I have altered the code not at all, so this is exactly the way an AI would behave.But.. it's controlled by a player! So yeah, he's constantly moving and jumping around. It looks really awesome. What struck me as odd was I was immediately confused which controller was controlling which actor.. because they are indistinguishable when I used that update code.
Torque 3D Owner Will O-Reagan
Modern Intrigues
First I set up some properties for MovingLeft and right, to match the _moveLeft and _moveRight.. etc, plus _jump and _downJump, and updated those from the network player every step, and it works like a charm (except if the actor dies, but I can worry about that later).
Well, heres my updating code.. if anyone's interested. The key was not trying to update the states manually.
networkPlayerActorComponent.MovingRight = _player.MovingRight; networkPlayerActorComponent.MovingLeft = _player.MovingLeft; networkPlayerActorComponent.MovingUp = _player.MovingUp; networkPlayerActorComponent.MovingDown = _player.MovingDown; networkPlayerActorComponent.Jumping = _player.Jumping; networkPlayerActorComponent.JumpingDown = _player.JumpingDown; networkPlayer.Position = _player.Position;