How to impliment Gravity in a game in which the player moves by changing velocity? [duplicate] - pygame

This question already has answers here:
How to fix character constantly accelerating in both directions after deceleration Pygame?
(1 answer)
Pygame game help: Easing/Acceleration
(1 answer)
How do you properly implement gravity to a free floating space object and some sort of friction when thrusting in opposite direction
(1 answer)
Closed 1 year ago.
The game is a tile based 2d platformer.
Separately handling the velocity and acceleration on the player causes it to bug out.
This happens cause the player's velocity becomes big enough to phase through the platform.
How do I go about checking if the player is grounded or not, since I can change the y velocity of the player to 0.
Currently I have to manually set the velocity to 0 after every frame and as a result I cant implement gravity

Related

How do you make a rect move to the mouse when dragged in pygame? [duplicate]

This question already has answers here:
pygame rect is slipping out of the mouse curser
(2 answers)
Drag multiple sprites with different "update ()" methods from the same Sprite class in Pygame
(2 answers)
Closed 18 days ago.
I am trying to make a rect move to the mouses location as long as it is being dragged. How can I do this? The loop I am going to store this in is
while stuff.collidepoint(pygame.mouse.get_pos()):
I tried to make it drag but my brain would not work

How to create a circular constrained paddle using Box2D?

I am trying to create the ball and paddle setup just like in Circle Pong. It is basically a paddle which revolves about a circular path as if it is tied by a rope to the center of the circular orbit.
here is a video of Circle Pong: https://www.youtube.com/watch?v=9sitwBolywY
I want to use Box2D for the physics. How do I constrain the paddle to move in a circular orbit? I might even want to have multiple paddles for a circular orbit (with a fixed angular distance from each other).
A distance joint with a static central body won't work because the central body might obstruct / come in the way of the ball. Also it won't work with multiple paddles.
Any ideas?
for the first I'm not sure if you need physics engine in game like this at all - it seems to be such simple that simple scene2d actions + setting origins should be enough - please notice that it would improve your game performance and make it easier to deploy.
But - if you are sure you want to use box2d please consider using distance joint with a body which has a fixture with isSensor = true. It won't take part in collision calculations, letting you to achieve your point.
FixtureDef fixtureDef = yourMaterial;
fixtureDef.shape = yourShape;
fixtureDef.isSensor = true;

Decimal numbers not adding correctly in AS3 [duplicate]

This question already has answers here:
Is floating point math broken?
(31 answers)
Closed 7 years ago.
In my program, I have a score multiplier variable of type 'Number'
When I try to add 0.1 to it, I have a problem.
Here is the code:
scoreMultiplier += 0.1;
trace(scoreMultiplier);
scoreMultiplier is originally set to 1, and after the first run through, I correctly get a value of 1.1. However, the second time, the trace shows 1.2000000000000002, and the next time 1.3000000000000003.
There is no other code which modifies scoreMultiplier. This is a problem, first because it is shown on my game screen and goes off the screen, and second because if conditionals where scoreMultiplier==2 for example do not work due to the bizarre fault in the addition.
If anyone knows what's causing this, or at the very least how to truncate the value to 1 decimal place, that would be great.
Flash does not like floating points. At all. Avoid them as much as you can.

AS3 Predictive collisions (Sweep testing)

I'm making a basic platformer engine in AS3, and I'm currently implementing gravity. The gravity currently lets the player sink a few pixels into the ground when it lands (depending on the player's speed), and I don't want that.
I want to be able to test collisions 1 frame ahead of time (sweep testing), and if a collision will happen in the next frame, I want the player to stop 0px into the ground, regardless of the player's speed.
I also want pixel-perfect collisions that take the shape of the terrain, so I've been using Corey O'Neil's Collision Detection Kit (CDK), which works very well for detecting collisions, but I can't work out how to make it predict them. I'm not sure if this is the best library to use.
I'm not sure about Box2D; I feel it's too much for what I want.
Any idea of how can I do pixel-perfect sweep tests in AS3?
Box2D should be pretty good for small projects as well, also in case if you wish to scale up later...
If you need quicker dive in, have a look at Quick Box 2d.
There are couple of good tutorials (here & here) as well.
I want to be able to test collisions 1 frame ahead of time (sweep
testing), and if a collision will happen in the next frame, I want the
player to stop 0px into the ground, regardless of the player's
speed.
In you game loop, where you are checking the colisions, just add the movement that will be done in the next frame, the current Y speed.
Something like this:
if(currentYSpeed + player.y >= ground.y)
{
player.y = ground.y
}else
{
player.y += currentYSpeed;
}

box2d: How do I rotate an object on specified amount of degrees smoothly

I wonder if box2d has some options for doing that?
I am trying to apply angular velocity atm, but don't know where to stop rotating :(...
So object which needed to rotate to 90 degrees, can't stop rotating....
Well I did it adding small angular velocity and comparing to current angle of the object... Not sure why I've asked the question. Everything worked well!