Question About Physics!

0 favourites
From the Asset Store
Logo Quiz with 150 prepared logos and answers, automatic question and answer mixing
  • Hi there!

    I am making a game using Physics, which is new to me, and I have some minor problems.

    I use "Physics Force" to move the player Left and Right.

    I use "Physics Impulse" to make the player Jump.

    The problem I have is when the player is moving fast and I want to change the direction of the player, it takes forever. Well, I'm exaggerating but it takes too long. If I move Right and I suddenly want to move Left - I want the player to move Left ALMOST immediately. Do you understand what I mean?

    I would be extremely grateful for any help you can give me and merry xmas to you all

    Thanks in advance,

    Tomolo Games

  • Just to clarify, I want the player to be able to slow down much quicker when I for example press Left and the player is moving Right. I also have some problems with the speed. I would like to set a max speed, I don't want the player to just move faster and faster.

    Thanks again,

    Tomolo Games

  • Use "Physics -> Set velocity", it works instantly.

    For example to move left at speed 100, use "Set velocity x=-100, y=0"

    To move at angle: "Set velocity x=100*cos(angle), y=100*sin(angle)"

    You'll have to modify these formulas if you want acceleration/deceleration.

    Making platform game with physics may be tricky. Have you considered using Platform behavior?

    Platform with Physics don't work well together, but you can disable Platform and enable Physics when you need to interact with other physics objects.

    Or you can make two sprites - one main sprite with Platform behavior and an invisible clone sprite with Physics behavior, that will follow the main sprite.

  • Yaaay, I was hoping you'd be the one helping me out because you've helped me out once before with a previous game with great success

    Unfortunately, "Set Velocity....." didn't work so well. I have now figured out how to set a maximum speed so that's great. The acceleration/deceleration part is still bugging med though.

    I can't use Platform Behavior because I'm constantly using the "Physics" so I will just have to figure it out. The biggest problem isn't the acceleration/deceleration part though. The biggest problem is when I jump. It works great when I'm on "flat" ground looking like this _____ but when I jump and I'm going up a "hill", looking like this /, I jump super-high for some reason.

  • "Set velocity" should work, but you need to regulate the speed and apply it every tick, otherwise movement can be slowed down by friction, damping etc.

    I'm guessing when your character moves up a hill, it has some Y velocity, so when you apply an impulse, it adds to Y velocity, making the jump too high. You can try setting Y velocity to zero before the jump, or decreasing impulse strength if character has Y velocity.

  • You are always awesome! I fixed the problem with Jumping too high

    The problem I have with "Set velocity" is that I can't jump when I'm using that method?

  • I'm sooo happy now because all the problems I had when I created this thread is now solved. I came up with a great solution to solve the acceleration/deceleration-problem. Sooo proud right now

    Thank you for helping me out with the Jump-problem I had btw

  • No worries!

  • Hi again

    I use "Physics Impulse" in order to Jump. The impulse is "50 at angle 270" so the player Jumps straight up. When the player is moving (rolling, it's a ball) up a "hill" the player speeds up and I don't want the player to gain speed. The impulse is only suppose to move the player upwards, not forwards. Do you think it's because the angle 270 "interferes" with the "hills" angle and because of that the impulse isn't at angle 270?

    If so, do you know if there's a way to fix that? I have been trying all kinds of things for over 10 hours now and I'm not exaggerating haha!

  • Physics objects behave like real-life objects. If a real-life ball is rolling forward and you apply impulse (hit it from below), the ball will jump up and forward, because it has forward momentum.

    So if you don't want it to move forward when jumping, I think you need to remove its horizontal velocity, set it to 0.

    It's only a guess, since I don't have your capx to test.

  • Thank you for replying, again

    If the ball is rolling, I want the ball to jump up and move forward in the same speed as it was going when I first jumped. If I set the X Velocity to 0 it doesn't keep moving when I jump.

    If the ball is rolling up the hill it can go a certain distance up the hill. If the ball is jumping while going up the hill it can go further than if it was just rolling. Do you understand what I mean?

    I you have the time and energy to check out the capx, I'd be more than happy to send it to you from my e-mail

  • I made a video to show you better.

    The first time I jump when I'm going up and the second time I just let the ball roll.

  • If the ball is rolling up the hill it can go a certain distance up the hill. If the ball is jumping while going up the hill it can go further than if it was just rolling.)

    I see this on the video, thanks. But I don't understand your problem.

    Do you want the ball to go further when it's jumping? (as it does now)

    Or do you want it to move the same distance, no matter if it's jumping or rolling?

    Or should the distance be actually shorter when the ball is jumping?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I want the ball to go, at least more or less, the same distance whether you are jumping or just rolling.

    The idea of the game is to get "coins" that will give you a little speed boost (physics impulse) so that you can go all the way to the end/goal. The way it is now, you can in some places miss the coins but if you just jump up the hills instead you'll make it anyway. It ruins everything

  • There are many ways to alter horizontal speed when jumping. How you want to do it it's up you.

    In your event #2 where you reset velocityY before applying impulse, you can set X component of the velocity to one of these values:

    1. Player.Physics.VelocityX*0.75

    this will decrease horizontal speed by 25% for any jump.

    2. Player.Physics.VelocityX+(Player.Physics.VelocityY/2)

    this will decrease the speed if ball is rolling up, increase the speed if ball is rolling down, have no effect if ball is rolling forward.

    The bigger is the slope angle, the more is the increase/decrease in speed.

    3. Player.Physics.VelocityX-abs(Player.Physics.VelocityY/2)

    this will decrease the speed if ball is rolling up or down

    4. Player.Physics.VelocityX+min(Player.Physics.VelocityY/2, 0)

    this will decrease the speed only if ball is rolling up

    Note, that if hill angle is very steep, the ball can actually stop or move backwards on jump. You can add clamp() to these formulas to prevent this from happening. For example:

    Player.Physics.VelocityX+clamp(Player.Physics.VelocityY/2, -100, 0)

    Of course you can choose different values instead of "/2" and "*0.75"

    And you'll probably need to make adjustments to some parts of your layout as the length of jumps will change.

    One more thing - don't use huge sprites for background, use TiledBackground.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)