#Collisions issue - clipping through objects 10 pixels while movement key held and going back
1 messages ยท Page 1 of 1 (latest)
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
Here is an AI assisted attempt to answer your question ๐ค. Maybe it helps! In any case, a human is on the way ๐. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
time I collide with an object and then move back, my character clips through the object by about 10 pixels.
This issue is likely occurring because your collision detection and response code is not properly handling the situation when your character moves back after colliding with an object. Here are a few possible reasons for this issue and some suggestions to fix it:
-
Collision detection: Make sure that your collision detection algorithm accurately detects collisions between your character and objects. Double-check that you are using the correct bounding boxes or shapes for both your character and objects.
-
Collision response: When a collision is detected, you need to handle the response properly to prevent your character from clipping through objects. One common approach is to move the character back along its previous movement direction until it no longer collides with the object.
For example, if your character moves left and collides with an object, you can move it back right until it no longer overlaps with the object. You can do this by checking for collisions in smaller increments (e.g., 1 pixel) until there is no longer a collision.
-
Movement speed: If your character's movement speed is too high, it can cause issues with collision detection and response. Consider reducing the movement speed or adjusting the collision response code accordingly to handle higher speeds.
-
Frame rate: If your game has a low frame rate, it can also lead to inaccurate collision detection and response. Ensure that your game runs at a consistent frame rate to improve collision accuracy.
-
Debugging: Use print statements or debuggers to track the values of variables related to collisions (e.g., position, velocity) during runtime. This will help you identify any inconsistencies or errors in your code that may be causing the clipping issue.
By addressing these potential issues, you should be able to fix the problem of clipping through objects when moving back after a collision in your game.
you are probably moving after dong the collision check, so you do the collision check and move the player outsie the box, and then apply the movement, so the player ends up 10pixels in the box
show your code
where is Collisions() called ?
where is Movement() called ?
what is p1 ?
ah
you are displying the player before the bound checking
so the player is correctly placed
but what you see is before you did the bound checking
yes because then you have this problem โ
you have to call draw after everything else
Closed the thread due to inactivity.
If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you ๐