-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace HC with either bump or manually written collision detection system. #3
Comments
When using HC to rebound the ball, sometimes (when frame rate drops) the ball can ignore wall collision response, causing some weird behaviors… like losing the ball. I've noticed you're updating the Wiki with new content (such as using LÖVE's default physics). Since love already has its own game loop function ( |
Yes, this is also one of the reasons I want to replace HC with something different. The problem is following: during the update cycle, I update the positions of the game objects function Ball:update( dt )
self.position = self.position + self.speed * dt
.....
end If the product function love.update( dt )
local min_dt = 0.01
if ( dt > min_dt ) then
dt = min_dt
end
ball:update( dt )
platform:update( dt )
.....
end I believe, that way the collisions on low framerate should be resolved correctly. However, the bug also can happen when the speed of the ball becomes high enough. function love.keyreleased( key, code )
if key == 'up' then
ball.speed = ball.speed + 100 * ball.speed:normalized()
print( "current ball speed: ", ball.speed )
end
end On my machine, the ball passes through the walls somewhere around The correct solution requires to implement a more complicated collision detection algorithm, e.g. continuous collision detection. The simple collision detection algorithm I describe in parts 1-3 and 1-4 is also susceptible Hope, this answers your question. Regarding the simple code for collisions I use in parts 1-3, 1-4, I would prefer to avoid the term "LÖVE's default physics" because it can be confused with |
Yeah, now that I've finished replacing HC library, I can see that indeed we're not using the Thank you for the detailed answer… |
Hi! I am now following this tutorial (great job by the way!) and I encountered the same problem: when the speed of the ball increases the ball sometimes goes beyond the walls.
In all this cases the shift sign is not the one that it should be in order for the ball to bounce on the wall. I managed to solve this issue manually with this function:
The function is called at the start of the collisions.resolve_collisions function so if the ball is bad positioned it is positioned again in a way that it can bounce on the wall. At least for me this is working, but I just started learning lua and LOVE and I'm not a programmer so I'm not really an expert or anything, I just hope this is somehow useful. |
Yes, the current collision detection algorithm doesn't work correctly for objects moving at high speed. It seems to me, the problem is not limited to ball-walls collisions but also concerns ball-platform and ball-blocks collisions. That is, at high enough speed the ball can pass not only through walls, but also through platform and blocks.
While the solution you propose allows to keep the ball inside the game area, it seems it won't handle ball-blocks and ball-platform collisions correctly. One way to deal with this problem for all types of collisions is to determine whether or not a path the ball covers during a single update cycle intersects any other objects. I believe, this can be implemented in the following way. function ball.update( dt )
ball.possible_position_x = ball.position_x + ball.speed_x * dt
ball.possible_position_y = ball.position_y + ball.speed_y * dt
end Before actually placing the ball into this possible new position function ball.move_to_possible_position()
ball.position_x = ball.possible_position_x
ball.position_y = ball.possible_position_y
end it is first necessary to check for intersections of the line segment between the old and new positions and any other game objects. This can be done in the functions responsible for collisions between various objects -- (this is a pseudocode, not an actual code).
function collisions.ball_platform_collision( ball, platform )
local intersects = collisions.check_trajectory_intersections( platform, ball )
if intersects then
ball.resolve_intersection( platform )
end
end In the I believe such method should work, but I'm not sure about details. I'll try to implement it and if there is any noticeable improvement I'll include it as an appendix. |
I noticed the problem only with the ball-walls collision so I tried to solve only that. |
Yes, I have been thinking to write a couple of appendices illustrating a typical implementation of classes in Lua and how to use them to represent game objects. Lua is a bit different from other programming languages in it's approach to classes and it has taken me quite some time to understand how it works. Actually, in the initial version of this tutorial classes have been introduced early on. While I have been thinking to illustrate classes implementation, I don't think I'm going to discuss usual OOP design issues (inheritance, etc). In any case, regarding the classes and OOP, I would suggest to consult Programming in Lua (the first edition is available online ), numerous tutorials on Lua-users wiki or, probably, this more recent introductory article. |
No description provided.
The text was updated successfully, but these errors were encountered: