3
\$\begingroup\$

So I'm currently building a bare-bones functioning game that involves simple platforming. Quite literally a box moving left and right and jumping. I'm using Clickteam Fusion 2.5, and I know there's an option to assign platforming movement to an active object, but I honestly do not enjoy implementing that feature one bit.

So instead I'm opting for simply adding or subtracting from the X and Y coordinates of the player object while the left and right arrow keys are held down for side-scrolling movement.

However, I have yet to figure out how to use this same method for jumping and gravity. I know being able to jump would be running an event that occurs after hitting a certain key, which takes in the current Y-coordinate of the player and runs it through a parabolic formula. And then gravity would simply be constantly subtracting from (or I guess in Fusion's case, adding to) the current Y-value of the player object while the frame is running. So the question simply is where and how do I implement these things in order to create jumping and gravity. I figure there's a correct syntax for a parabolic formula when creating an event after "jump" is pressed, but for the life of me I can't figure it out. As for gravity, I'm completely lost. I have managed to get down stopping movement when colliding when another object so that is not an issue.

Thanks and appreciation in advance.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

It sounds like you want to implement your own physics instead of using what's built in. Fortunately, you don't have do any kind of parabolic calculation when jumping (unless you want to project the path of the character or something like that). Instead, you let physics run its course which will naturally create parabolic shapes. Here is some example code for very simple physics:

Vector2 velocity = Vector2.new(0, 0);
Vector2 acceleration = Vector2.new(0, 0);
bool onGround = true;

function onJump() {
    velocity.Y = jumpVelocity;
    onGround = false;
}

function onLand() { 
    velocity.Y = 0;
    onGround = true;
}

function update(delta) {
    if(!onGround) {
        acceleration = Vector2.new(0, -gravity);
    } else {
        acceleration = Vector2.new(0, 0);
    }

    velocity += acceleration * delta;
    character.position += velocity * delta;
}

What's fun is that you can use this same thing for your lateral velocity as well. Instead of merely shifting the character over by a set amount, you can just adjust the velocity in the X direction and the update loop will take care of updating the position.

This is by no means a complete physics system, but should be a good start if you want to implement physics yourself.

\$\endgroup\$
1
  • \$\begingroup\$ Clickteam Fusion doesn't really have code in the same way as other engines, so while your answer is useful in a general sense, it's not very applicable to Clickteam Fusion Specifically. Maybe you could explain what each part of your example code does, but try to explain it to someone who has literally no experience with any programming language? \$\endgroup\$
    – Jonathan
    Apr 14, 2021 at 19:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .