Problem with Power Station example

rated by 0 users
This post has 5 Replies | 3 Followers

Top 25 Contributor
Posts 196
SunBurn_Pro_Licensee
ggblake Posted: 08-19-2010 11:32 AM

I have extracted some of the code to use in a BEPUPhysics version. My triggers work fine....once.

 

Wherein the Power Station code is a trigger that has been fired reset so it can be fired after the relapse time has expired ?

Top 10 Contributor
Posts 4,854
Employee
SunBurn_Studio_Licensee

Hi ggb,

I'll ping Ross about this, he's the resident expert on the Power Station demo. :)

Should hear back from us soon!

Follow me on Twitter – development and personal tweets
Awesome XNA Videos – Lighting, Rendering, and game videos

Top 25 Contributor
Posts 245
Employee

Triggers reset automatically whenever FireActions is called, if the recharge time has been exceeded.

I'm not sure what the problem could be without more information. What changes have you made to the code and how are you using the triggers? What triggers do you have setup? Right now all I can suggest is that you make sure Update is called on the triggers and that both Update and FireActions are passed the current GameTime struct.

Top 25 Contributor
Posts 196
SunBurn_Pro_Licensee

What variable is "reset"  in FireActions?

 

here's my FireActions:

public void FireActions(string target, GameTime gametime)
        {
            if ( _Actions == null )
                return;

            if ( gametime.TotalGameTime.TotalSeconds - _LastTrigger < _RechargeTime )
                return;

            _LastTrigger = (float)gametime.TotalGameTime.TotalSeconds;
            _Triggered = true;

            bool retarget = !String.IsNullOrEmpty(target);

            for ( int t = 0; t < _Actions.Length; t++ )
            {
                _Actions[t].Triggered = false;
                if ( retarget )
                    _Actions[t].SetTarget( target );
            }
        }

here's the update loop

private void UpdateWorldObjects()
          {
              bool  pressed = false;
              triggerfired = false;
          
            
              if (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed)
              {
                  pressed = true;
                  game.Brain.neuralnet.MakeKnown("showA", "false");
              }

         
              for (int i = 0; i < WorldObjects.Count; i++)
              {
                  WorldObjects[i].Update();// gets gametime from a game property in the trigger class
                  if (!triggerfired && WorldObjects[i].Active && WorldObjects[i].IsTrigger() && pressed )
                  {
                    
                      if (pressed)
                      {
                          Trigger trigger = WorldObjects[i] as Trigger;
                          if (!trigger.isClose) continue;
                          trigger.FireActions(null);
                          triggerfired = true;
                      }

                  }
              }
           
            

          }

Here's my trigger creation code:

Actor elevator = new Actor(game, space, "models/flyingmat", new Vector3(18, 1, 18), new Vector3(18, 1, 18), new Vector3(0, 15, 0), 1, 0, "elevator");
           
Actor sw = new Actor(game, space, "models/switch", new Vector3(4, 4, 4), new Vector3(4, 4, 4), new Vector3(-100, 50, 200), 1, 0, "switch");


            Trigger lift = new Trigger(game, sw, "lift", 15);
            MoveInfo mi = new MoveInfo(new Vector3(0, 1, 0), new Vector3(0, 0, 0), 5, 10);
            TriggerAction startlift = new TriggerAction(game, elevator, ActionType.Move, 4, mi);
            lift._Actions.Add(startlift);
            game.SM.worldtriggers.Add(lift);
            Trigger lower = new Trigger(game, gascan, "lower", 15);
            MoveInfo mi2 = new MoveInfo(new Vector3(0, -1, 0), new Vector3(0, 0, 0), 50, -20);
            TriggerAction startlower = new TriggerAction(game, elevator, ActionType.Move, 0, mi2);
            lower._Actions.Add(startlower);
            game.SM.worldtriggers.Add(lower);

instead of a bounding box I use entities via BEPUPhysics to detect the triggering and to apply

physics to the object. The lift will lift but the second trigger will not fire, and the first trigger will not fire a second time even after the recharge time.

 

 

ADDENDUM:

Found my glitch. Was actually in my Move/Startmove code. Triggers seem OK now but still

need to get my head around which variable is reset, in your response above in case I need to reset it elsewhere in code

Thanks

Top 25 Contributor
Posts 245
Employee

The second if statement in FireActions checks to see if the recharge time has passed, and if so the trigger is fired. The loop at the bottom of the function goes through all of the trigger's actions and resets them.

From what I can see, the second trigger fires correctly but its MoveInfo is invalid. Both move speed and move distance should be positive, that -20 will cause the move to be ignored.

[Edit]

Good to see you got it fixed.

Top 25 Contributor
Posts 196
SunBurn_Pro_Licensee

Many thanks. It wasn't only the move info, but the actual Move code as well

Page 1 of 1 (6 items) | RSS