How to know the player state in some class.
by Ricardo Bencz · in Torque X Platformer Kit · 05/01/2010 (10:56 am) · 16 replies
Hi.
I would like to know how can I get the player state in the DrillHeadKillComponent.cs, because I will verify the state, and, depending it, the oponent will die or not.
What's the options?
I would like to know how can I get the player state in the DrillHeadKillComponent.cs, because I will verify the state, and, depending it, the oponent will die or not.
What's the options?
#3
if(player.CurrentState )
{
_drillActor.TakeDamage(100.0f, dragon.Actor);
}
any ideas?
09/08/2010 (2:32 am)
would you be able to cure the frustration caused by not knowing the syntax to do the state check cos i'm stumped. i've got this so far but can't for the life of me work out the syntax for the if statement:if(player.CurrentState )
{
_drillActor.TakeDamage(100.0f, dragon.Actor);
}
any ideas?
#4
09/08/2010 (3:29 am)
I think it depends, do you want to know the Physics state of the actor? If so, here are your options.if (player.CurrentState is OnGroundState)
{
}
else if (player.CurrentState is InAirState)
{
}
else if (player.CurrentState is OnLadderState)
{
}
else if (player.CurrentState is DeadState)
{
}
#5
i wasn't explicitly looking for a physics state more an animation state but am i right to think that i can check the physics then check the animation?
i had a go at trying these but i'm getting errors with OnGroundState etc saying the namespace doesn't exist which i take it means i've done something wrong in my setup for the check
09/08/2010 (5:19 am)
what a quick reply you're a championi wasn't explicitly looking for a physics state more an animation state but am i right to think that i can check the physics then check the animation?
i had a go at trying these but i'm getting errors with OnGroundState etc saying the namespace doesn't exist which i take it means i've done something wrong in my setup for the check
#6
i think, although my knowledge on the matter is limited at best, this is in reference to my use of the actorcomponent (player) rather than a variable. at least this is what i've gathered through continually getting the error.
i have been trying things along the lines of (swipe being my attack):
if (player.CurrentState == FSM.Instance.GetState(player, "swipe"))
but obviously this can't be correct
09/08/2010 (5:30 am)
i've been doing a lot of work on this and anything i get to be error free in the code ends up causing the error "object reference not set to an instance of an object" when i collide with an enemy.i think, although my knowledge on the matter is limited at best, this is in reference to my use of the actorcomponent (player) rather than a variable. at least this is what i've gathered through continually getting the error.
i have been trying things along the lines of (swipe being my attack):
if (player.CurrentState == FSM.Instance.GetState(player, "swipe"))
but obviously this can't be correct
#7
If you want to check the animation states, check the animation Manager's state, the actor component itself only keeps track of physics states.
Another note, if you are interested in AI's, the ActorAIController is another state machine.. so there are possibly three state machine's you can be dealing with, its important to know which one you are interested in.
09/10/2010 (2:42 am)
Yeah your issue is that the == doesn't have a way to compare states, or if it does, I have not checked yet.If you want to check the animation states, check the animation Manager's state, the actor component itself only keeps track of physics states.
Another note, if you are interested in AI's, the ActorAIController is another state machine.. so there are possibly three state machine's you can be dealing with, its important to know which one you are interested in.
#8
09/10/2010 (2:46 am)
you can try adding the using statement at the topusing GarageGames.Torque.PlatformerFramework;
#9
i now see all the trouble people have had with implementing attack states with the psk and i am greatly regreting trying to achieve it
thanks a lot for your help i tip my hat to you
09/10/2010 (8:27 am)
well the == not working certainly puts a spanner in the works(particularly as i am not aware of another method for comparision) and the using statement already appears to be there.i now see all the trouble people have had with implementing attack states with the psk and i am greatly regreting trying to achieve it
thanks a lot for your help i tip my hat to you
#10
if (CurrentState.StateName == "AttackState")
{
//do something..
}
hope this helps.
09/11/2010 (6:53 am)
Another strategy is using the StateName property, and doing a comparison on that... ie:if (CurrentState.StateName == "AttackState")
{
//do something..
}
hope this helps.
#11
ActorComponent player = TorqueObjectDatabase.Instance.FindObject<ActorComponent>("Player");
then going into the if statement format you've suggested.
i'm still trying to figure out how to go about changing this initial line so that the animation manager is referenced.
thanks again
09/13/2010 (5:31 am)
that does help and seems to function ok though i can't completely check. i think my issue is with what i'm trying to check is still not the animation manager as you've suggested earlier. at the moment i'm going:ActorComponent player = TorqueObjectDatabase.Instance.FindObject<ActorComponent>("Player");
then going into the if statement format you've suggested.
i'm still trying to figure out how to go about changing this initial line so that the animation manager is referenced.
thanks again
#12
if (player.AnimationManager.StateName == "AttackState")
{
//code here.
}
09/13/2010 (8:06 pm)
one you get the player (actor component), simply call,if (player.AnimationManager.StateName == "AttackState")
{
//code here.
}
#13
if(player.AnimationManager.CurrentState.StateName == "attackstate")
{
}
(i couldn't go from animation manager to statename without currentstate)
but i still get the 'object reference is not set to an instance of an object' error when i collide with an enemy no matter which state i am in.
09/14/2010 (1:33 am)
see thats the sort of thing i thought would work and i've tried:if(player.AnimationManager.CurrentState.StateName == "attackstate")
{
}
(i couldn't go from animation manager to statename without currentstate)
but i still get the 'object reference is not set to an instance of an object' error when i collide with an enemy no matter which state i am in.
#14
09/14/2010 (1:48 am)
You should place a break point, and check where you are getting the null reference (if it is in fact a null reference). Once you have placed the breakpoint, you should be able to hover your mouse over variables, and see which ones are valid, something you may have changed, or altered. Or it could be a different object reference.
#15
09/14/2010 (5:10 am)
ok i think i've done what you've suggested. i created the breakpoint and ran into an enemy it went to the if statment line and is giving the player as null
#16
ok so i think i was going about it the wrong way i needed to use this line instead:
ActorComponent player = theirObject.Components.FindComponent<ActorComponent>();
then go:
if(player.animationmanager.currentstate.statename == "swipe"
{
_drillActor.TakeDamage(_takeDamageOnLand, dragon.Actor);
}
thankyou very much for your help you have been my obi wan
09/17/2010 (1:43 am)
i figured it out!!!!!ok so i think i was going about it the wrong way i needed to use this line instead:
ActorComponent player = theirObject.Components.FindComponent<ActorComponent>();
then go:
if(player.animationmanager.currentstate.statename == "swipe"
{
_drillActor.TakeDamage(_takeDamageOnLand, dragon.Actor);
}
thankyou very much for your help you have been my obi wan
Torque Owner Olivier Giguère-Durand
Reverse Impact
player.CurrentState;
if you named it Player in your scene and assuming it has an actor component ;) If not, you still got the gist. If you want detail that is available through another component, just change the 2 "ActorComponent" bits to that :)
Hope it helps.