Game Development Community

question

by __--__ · in Torque X Platformer Kit · 09/28/2008 (8:10 pm) · 19 replies

...

#1
10/07/2008 (7:21 am)
Ok I'm frustrated - Anyone have any ideas?
#2
10/21/2008 (5:04 pm)
I've been trying to integrate this function for a month but have had no success. I get confused quickly when I'm looking through all of the code in any given component - Anything I try to add either conflicts with existing code or causes another part of the component to stop working. I can see how a given line of code functions, but when they're all put together it quickly becomes overwhelming. Anyone? Suggestions!?
#3
11/25/2008 (1:28 pm)
Have you taken any programming courses? If not, I suggest you take about a year of programming to get to object oriented programming in C++ or in Java, which are very similar to the C# in XNA. That should really get you moving.
#4
12/01/2008 (11:22 am)
Anyone have any tutorials on accomplishing this "Mario-style" jump?
#5
12/02/2008 (12:07 pm)
Assuming that you want the player to jump further the longer the button is pressed, while in the air. Below is some of the code in the starter that you need to look at.

//ActorController
protected virtual void _jump();

//in actor's physics states
if (actor._Jumping)
                {
                    // jump up
                    actor._actor.Physics.VelocityY = actor._groundVelocity.Y - actor._jumpForce;

//in the air state you would need to look at this line:
// apply gravity
actor._actor.Physics.VelocityY += actor.Gravity * elapsed;

What you need to do is monitor how long the actors controller's "jump" method is called, then keep applying the "actor._jumpForce" every tick in the air state method.

This doesn't look easy to do. If your just starting out with c#, then I would recommend starting out with an easier part of your game then coming back to this.
#6
12/27/2008 (9:45 pm)
I'm working on a similar problem to the OP. In my case, rather than tie jump height to button press time I want to tie the jump height to the amount the Xbox 360 left trigger has been pulled. So, if the trigger is pulled all the way, the player will jump as high as possible; if it's only pulled 50% the player jumps half his maximum possible height, etc, etc.

So far this is what I've got.

ActorComponent.cs has a line:

actor._actor.Physics.VelocityY = actor._groundVelocity.Y - actor._jumpForce;

This line does the actual jumping. It is called from a method, _jump(), in ActorController.cs which, in turn is called from PlayerController.cs.

So we have something like this:

1. PlayerController.cs issues a jump command by calling the _jump() method in ActorController.cs.
2. ActorController.cs takes this and calls the Jump method in ActorComponent.cs, which tells the FSM in ActorComponent.cs to make the player jump using the line of code shown above.

To get my player to jump based on how far the game pad trigger is pulled I've updated all these various jump methods to take a float parameter called jumpFactor. JumpFactor is the amount the trigger is pulled (0 being not pulled, 1.0 being fully pulled). This gets passed along as I outlined above until we get to the line of code the does the actual jumping, which I have updated to add my jumpFactor:

actor._actor.Physics.VelocityY = actor._groundVelocity.Y - (actor._jumpForce * actor._jumpFactor);

Now this is where I am stuck. I have two problems. The first is that the trigger is analog. What this means from a programming standpoint is that the reported value for the trigger is not immediately known on the first tick of the game engine. In other words, if you press the trigger all the way down it may be a few ticks before a value of 1.0 is reported. In the meantime you get all the intermediate values. This is not such a problem, as I could just update the jumpFactor as I go along during the jump.

The real problem is that the _jump() method call in PlayerController.cs is only called on the first tick of the jump. I know that code block the method call is in gets run every tick, but the method is not being called.

Any ideas would be greatly appreciated! If anything's not clear from my post, please ask -- it's midnight here and I've been working on this for hours.
#7
01/02/2009 (9:59 pm)
In my previous post I was looking to do a jump based on how far the trigger of the 360 game pad was pulled, but I've since discarded that idea in favor of the time-based approach of the original poster. Since this took me a good while to work out and it seems there were a few questions about how to approach this I put together a tutorial on TDN: Time-based Jumping with Torque X and the Platformer Starter Kit*

If anyone has questions, I'm watching this thread and I'll answer as best I can.

* My approach may (or more likely) or may not be the best and your results may vary.
#8
01/05/2009 (12:38 pm)
Nice tutorial. Very easy to follow. The way I would start to get around the hack would be to hold how long the button was pressed in the Controller, and when the button is released, call the "Jump" method passing how long the button was pressed for. Something like:
// set jump only on initial button down and button release
if (move.Buttons[0].Pushed)
{
    _timer += 1;
}
else if (_timer > 0)
{
    _jump(_timer);
    _timer = 0;
    
    if (movingDown)
    {
        _jumpDown();
    }
}

Or you could create another property in the actor.

Vishal
#9
01/05/2009 (2:01 pm)
Thanks for compliment. There are two reasons I didn't take the approach you posted. Depending on what you are looking to achieve neither of these issues is a deal-breaker (or any worse than my hack solution).

The first is related to game play mechanics so it may not be an issue for some. Taking your approach the actor will not jump until the jump button is released, so if you have a really long jump it will seem like the jump has to charge.

The second reason has to do with design philosophy. Strictly speaking, PlayerController.cs should only handle input for controlling the player and ActorComponent.cs, and components derived from it, should handle the logic for responding to input. PlayerController does not need to know how ActorComponent actually handles jumping, only that it will handle it. In other words, I'm striving for loose coupling between my components.
#10
01/06/2009 (11:40 am)
That's true. It all depends on the game!
#11
01/06/2009 (12:13 pm)
Thanks a ton for this - I added the code but I'm not yet able to test it, because I'm getting a few errors:

'GarageGames.Torque.PlatformerFramework.ActorComponent' does not contain a definition for 'IsMaxJumpTime'

I'm getting the same error for "_jumpDuration", "isJumping", and "_isJumping".

I went throught the code twice to make sure I implemented it correctly and I can't see where I went wrong - any help?
#12
01/06/2009 (12:36 pm)
Since you've double-checked everything it's likely that you put the code in the wrong place. I'll give you some line numbers, but yours will probably be slightly different from mine.

IsMaxJumpTime should be defined around line 1283. I put it immediately after ActorComponent's CopyTo method.

_isJumping, _jumpDuration and _jumpTime should be in a large block of variables that starts around line 2202 and ends around 2497. These vars are grouped according to use, so I put _isJumping under "movement flags" with _jump, _jumpDown, etc. _jumpDuration and _jumpTime both have to do with physics states so they are both under "physics state fields" which happens to be the next grouping after "movement flags"
#13
01/06/2009 (2:50 pm)
Wow - thanks for the quick reply! I defined them as you explained, and the only one that is giving me errors now is "IsMaxJumpTime".

here's how my code looks around line 1283:

public override void CopyTo(TorqueComponent obj)
{
base.CopyTo(obj);
ActorComponent obj2 = obj as ActorComponent;

obj2.IsMaxJumpTime = IsMaxJumpTime;

obj2.Gravity = Gravity;
obj2.MaxVelocity = MaxVelocity;

(etc, etc....)

so I must not be defining "IsMaxJumpTime" properly - suggestions?
#14
01/06/2009 (2:59 pm)
Ah! IsMaxJumpTime is a method, it doesn't go in CopyTo.

Just define it like this, after CopyTo:

public bool IsMaxJumpTime()
{
      if (_jumpDuration < _jumpTime)
      {
            return false;
      }
      return true;
}
#15
01/20/2009 (1:56 pm)
I got it to work, thank you so much Sean!!!!

BTW, I hit one snag though, I was actually about to post about this, but I figured out how to solve the problem.

"I followed you tutorial and it works with one problem. When I jump, the dragon is stuck in the first frame of animation (crouched), and the jump sound effect plays constantly as I hold down the space bar. Does anybody know what is causing this? I am sooooo close :D" -me 5 mins before fixing my problem

In one of your functions in the tutorial, I commented out the two lines that start with FSM (function posted below). I figured they were triggering the jump animation. Hopefully I didn't unknowingly screw up stuff by doing this, but it appears to work :D

// do pressure sensitive jumping
if (actor._Jumping && actor._isJumping)
{
actor._jumpDuration += (elapsed / 100);
// Separated from the main if clause for clarity
if (!actor.IsMaxJumpTime())
{
// jump up
actor._actor.Physics.VelocityY = actor._groundVelocity.Y - (actor._jumpForce * ((float)Math.Exp(actor._jumpDuration) / 2));
// set the appropriate animation state for jumping
if (Math.Abs(actor._moveSpeed.X) < 0.01f)
//FSM.Instance.SetState(actor._animationManager, "jump");
else
//FSM.Instance.SetState(actor._animationManager, "runJump");

actor._jump = false;
actor._jumpDown = false;
actor._onGround = false;
}
}
else
{
actor._isJumping = false;
actor._jumpDuration = 0.0f;
}
#16
01/20/2009 (2:31 pm)
@Daniel

Sounds like your jumping animation has a transition state. Mine doesn't so this isn't a problem for me. Glad to know it's working for someone else!
#17
01/20/2009 (4:45 pm)
yeah, I am just using the dragon that comes with the PSK to test out the time-based jumping. It has two frames and a sound effect is tied to the first frame. I was able to fix it quite easily though. Thanks again, this feature was an absolute must-have for my game and I got it in my game very quickly :D

Do you think there is any chance of making a tutorial for wall jumping? Like, http://www.youtube.com/watch?v=OhA7gmfPZKM from Megaman X4.
#18
01/20/2009 (7:30 pm)
@Daniel

Quote:
Do you think there is any chance of making a tutorial for wall jumping?

Yeah. It's been in the back of my mind for a bit now. My inspiration is this.

Right now I'm thinking I'll extend the base ladder component and create a ladder that scene objects cannot climb, only slide down over time. Haven't really been able to work on this at all as I'm concentrating on a different part of my game at the moment.
#19
01/20/2009 (7:45 pm)
Glad to hear its on your mind (even if its just in the back). Your timed-jump tutorial was excellently crafted :)

I like how your referencing N+, that's a great game with wall-jumping. I'll be the first one to read and utilize your tutorial if you make it :D