Skip to content

Fixing movement and collision issues in Metroidvania games

🎮 Need help with game physics or collision detection in your platformer? 🚀 Get Help Now

PD

PlatformerDev_Pro

Posted on July 23, 2025 • Advanced

🎮 Collision detection nightmare in my Metroidvania!

Hey everyone! I’m working on a Metroidvania-style platformer and I’m having serious issues with collision detection. Here’s what’s happening:

  • 🐛 When jumping on platforms, the character sometimes teleports below them
  • 🔄 Spamming jump while moving causes weird glitches
  • 📦 The hitbox seems misaligned with the sprite shape
  • 💥 Running into walls while jumping creates unpredictable behavior

I’ve tried adjusting the hitbox to match the sprite shape, but nothing seems to work! The glitches are most noticeable when you hold jump and move around quickly. Has anyone dealt with similar collision issues? 😫

CE

CollisionExpert_Maya

Replied 3 hours later • ⭐ Best Answer

I see exactly what’s happening @PlatformerDev_Pro! This is a classic collision detection issue. The problem is likely with your hitbox shape and collision order. Let me show you the proper solution:

🔍 Understanding the Problem

The teleporting issue occurs when your collision detection checks happen in the wrong order or when the hitbox doesn’t match the visual sprite properly.

flowchart TD A[🎮 Player Movement Input] --> B[Update X Position] B --> C[Check X Collision] C -->|Collision Found| D[Adjust X Position] C -->|No Collision| E[Update Y Position] D --> E E --> F[Check Y Collision] F -->|Collision Found| G[Adjust Y Position] F -->|No Collision| H[✅ Movement Complete] G --> H I[❌ Wrong Order] --> J[Update Both X & Y] J --> K[Check Collision] K --> L[🐛 Teleporting Bug!] style A fill:#e1f5fe style H fill:#e8f5e8 style L fill:#ffebee style I fill:#ffebee

✅ Proper Collision System

Here’s the correct way to handle movement and collision:

    // Main movement loop
when flag clicked
forever
handle horizontal movement
handle vertical movement
update animation
end

// Horizontal movement with collision
define handle horizontal movement
set [x velocity v] to [0]
if <key [right arrow v] pressed?> then
set [x velocity v] to [5]
end
if <key [left arrow v] pressed?> then
set [x velocity v] to [-5]
end

// Move horizontally and check collision
change x by (x velocity)
if <touching [Platforms v] ?> then
if <(x velocity) > [0]> then
repeat until <not <touching [Platforms v] ?>>
change x by [-1]
end
else
repeat until <not <touching [Platforms v] ?>>
change x by [1]
end
end
end
  
    // Vertical movement with collision
define handle vertical movement
// Apply gravity
change [y velocity v] by [-0.8]

// Jump input
if <<key [space v] pressed?> and <(on ground) = [true]>> then
set [y velocity v] to [12]
set [on ground v] to [false]
end

// Move vertically and check collision
change y by (y velocity)
set [on ground v] to [false]

if <touching [Platforms v] ?> then
if <(y velocity) > [0]> then
// Moving up - hit ceiling
repeat until <not <touching [Platforms v] ?>>
change y by [-1]
end
set [y velocity v] to [0]
else
// Moving down - hit ground
repeat until <not <touching [Platforms v] ?>>
change y by [1]
end
set [y velocity v] to [0]
set [on ground v] to [true]
end
end
  

🎯 Hitbox Optimization

The key is creating a proper hitbox that matches your character’s collision needs:

    // Create separate hitbox sprite
when flag clicked
forever
go to [Player v]
// Adjust hitbox size to be slightly smaller than visual sprite
set size to (85) %  // Makes collision more forgiving
end

// Use hitbox for collision detection instead of main sprite
define check platform collision
if <[Hitbox v] touching [Platforms v] ?> then
// Handle collision
end
  

⚡ Advanced Collision Techniques

For even smoother collision, use these pro techniques:

1. Pixel-Perfect Collision

    // Check collision one pixel at a time
define move safely (distance) in direction (angle)
repeat (abs of (distance))
point in direction (angle)
move (1) steps
if <touching [Platforms v] ?> then
move (-1) steps
stop [this script v]
end
end
  

2. Corner Correction

    // Fix corner snagging
define corner correction
if <touching [Platforms v] ?> then
// Try moving up slightly
change y by [3]
if <not <touching [Platforms v] ?>> then
// Success! Continue movement
else
// Restore position and stop
change y by [-3]
end
end
  

3. Coyote Time (Grace Period)

    // Allow jumping shortly after leaving platform
when flag clicked
set [coyote timer v] to [0]
forever
if <(on ground) = [true]> then
set [coyote timer v] to [6]  // 6 frames of grace
else
change [coyote timer v] by [-1]
end

// Allow jump if recently on ground
if <<key [space v] pressed?> and <(coyote timer) > [0]>> then
set [y velocity v] to [12]
set [coyote timer v] to [0]
end
end
  

This system will eliminate the teleporting bugs and give you smooth, professional-quality movement! 🎮

PD

PlatformerDev_Pro

Replied 2 hours later

@CollisionExpert_Maya This is absolutely incredible! 🤩

The separate X and Y collision checking was exactly what I was missing. I was trying to handle both axes at once, which was causing the teleporting issues. The hitbox optimization tip is genius too!

Implemented your solution and the movement feels buttery smooth now. No more glitches! Thank you so much! 🙏

GP

GamePhysics_Ninja

Replied 4 hours later

Excellent solution! Adding to this, here’s a debug visualization that helps identify collision issues:

    // Debug collision visualization
when [d v] key pressed
set [debug mode v] to <not (debug mode)>

// Show hitbox and collision points
when flag clicked
forever
if <(debug mode) = [true]> then
pen up
go to [Hitbox v]
set pen color to [#ff0000]
pen down
repeat (4)
move (50) steps
turn right (90) degrees
end
pen up
end
end
  

This lets you see exactly where your hitbox is and debug collision problems visually! 🔍

MG

MetroidvaniaMaster_Alex

Replied 6 hours later

For Metroidvania games specifically, don’t forget these essential features:

🎮 Metroidvania Movement Essentials:
  • Wall Jumping: Check for wall collision and allow upward movement
  • Ledge Grabbing: Detect platform edges and snap to them
  • Slope Walking: Handle angled surfaces smoothly
  • Variable Jump Height: Longer press = higher jump
    // Variable jump height
when flag clicked
forever
if <key [space v] pressed?> then
if <(on ground) = [true]> then
set [jump power v] to [15]
set [on ground v] to [false]
end
end

// Reduce jump power if key released early
if <<not <key [space v] pressed?>> and <(y velocity) > [5]>> then
set [y velocity v] to [5]
end
end
  

These additions will make your Metroidvania feel professional! 🏰

VB

Vibelf_Community

Pinned Message • Moderator

🎮 Master Game Physics and Collision Systems!

Outstanding discussion about collision detection and movement systems! For those wanting to create even more advanced platformer mechanics, our community can help you with:

  • 🏃 Advanced character controllers and state machines
  • 🌍 Complex level design and physics systems
  • ⚡ Performance optimization for large games
  • 🎯 Professional game feel and juice effects

📚 Related Topics

Ready to build amazing platformer games? Get expert guidance from our game development tutors in the Vibelf app!