コンテンツにスキップ

Fixing horizontal wall collision in Griffpatch platformer tutorial

このコンテンツはまだ日本語訳がありません。

💡 Stuck debugging platformer collision issues? Player getting trapped in walls? 🚀 Get Help Now

PD

PlatformerDad88

Posted on July 24, 2025 • Intermediate

🎮 Griffpatch platformer collision bug - player stuck in walls

Hey everyone! My son and I have been working through Griffpatch’s amazing platformer tutorial for hours, but we’re running into a frustrating issue. Everything seems to work correctly except the player keeps getting stuck horizontally in walls and ground! 😤

We’ve double-checked our code multiple times but can’t figure out what’s going wrong. The vertical collision works fine, but horizontal movement causes the player to clip through and get trapped.

Has anyone else encountered this issue? We’re following the tutorial exactly but something must be off. Any help would be greatly appreciated! 🙏

RC

RokCoder_Expert

Replied 54 minutes later • ⭐ Best Answer

I see the issue @PlatformerDad88! This is a very common problem when following the Griffpatch tutorial. The issue is with duplicate movement code that conflicts with the collision detection system.

🔍 The Problem Explained

Here’s what’s happening in your collision system:

flowchart TD A[🎮 Player Input] --> B[Set Speed X] B --> C[❌ Direct Movement] C --> D[change x by speed x] B --> E[✅ Safe Movement] E --> F[move - in steps custom block] D --> G[Player Moves] F --> H[Check Collision Each Step] G --> I[❌ No Collision Check] H --> J{Wall Detected?} I --> K[🚫 Stuck in Wall!] J -->|Yes| L[Stop Before Wall] J -->|No| M[Continue Moving] L --> N[✅ Safe Position] M --> N style A fill:#e1f5fe style C fill:#ffebee style D fill:#ffebee style E fill:#e8f5e8 style F fill:#e8f5e8 style K fill:#ffcdd2 style N fill:#c8e6c9

🛠️ The Solution

The move - in steps custom block is designed to replace the direct movement. You have both running at the same time!

Remove this conflicting code:

    // ❌ REMOVE THIS - it bypasses collision detection
change x by (speed x)
  

Keep only the safe movement system:

    // ✅ KEEP THIS - proper collision detection
move - in steps :: custom
  

🔧 Complete Movement System

Here’s how your movement code should look:

    // Main movement loop
when flag clicked
forever
// Handle input
if <key [right arrow v] pressed?> then
set [speed x v] to [5]
else
if <key [left arrow v] pressed?> then
set [speed x v] to [-5]
else
set [speed x v] to [0]
end
end

// Apply gravity
change [speed y v] by [-1]

// Move safely with collision detection
move - in steps :: custom

// Keep player on screen
if <(x position) > [240]> then
set x to [240]
end
if <(x position) < [-240]> then
set x to [-240]
end
end
  

📋 Custom Block: move - in steps

Make sure your custom block looks like this:

    define move - in steps
// Move horizontally in small steps
repeat (abs (speed x))
if <(speed x) > [0]> then
change x by [1]
else
change x by [-1]
end
if <touching [walls v] ?> then
if <(speed x) > [0]> then
change x by [-1]
else
change x by [1]
end
set [speed x v] to [0]
stop [this script v]
end
end

// Move vertically in small steps
repeat (abs (speed y))
if <(speed y) > [0]> then
change y by [1]
else
change y by [-1]
end
if <touching [walls v] ?> then
if <(speed y) > [0]> then
change y by [-1]
else
change y by [1]
end
set [speed y v] to [0]
stop [this script v]
end
end
  

🎯 Why This Works

  • Step-by-step movement: Moves one pixel at a time to detect collisions precisely
  • Immediate stopping: Stops movement the moment a wall is detected
  • Position correction: Backs up one pixel when collision is detected
  • Speed reset: Prevents momentum from carrying through walls

The key insight is that Griffpatch’s system replaces normal movement entirely - you can’t have both! 🎯

PD

PlatformerDad88

Replied 15 hours later

@RokCoder_Expert YOU’RE A LIFESAVER! 🎉 We removed that extra change x by (speed x) block and it works perfectly now!

My son is so excited that his character isn’t getting stuck anymore. Thank you so much for the detailed explanation - it really helped us understand what was going wrong! 🙌

GT

GameTutor_Mike

Replied 3 hours later

Great solution! 🎮 This is actually one of the most common mistakes when following platformer tutorials. Here are some additional debugging tips:

🔍 Common Platformer Debugging Checklist

  • Duplicate movement code: Make sure you only have ONE movement system
  • Wall sprite setup: Ensure your walls sprite has the correct name and costumes
  • Collision detection: Test with different wall shapes and sizes
  • Speed values: Start with small speeds (3-5) for easier debugging

Pro tip: Always test your collision system with simple rectangular walls first before adding complex level designs! 🏗️

VB

Vibelf_Community

Pinned Message • Moderator

🎮 Master Platformer Development

Excellent debugging work everyone! For those looking to create even more advanced platformers, our community can help with:

  • 🏃 Advanced movement mechanics (wall jumping, dashing)
  • 🎯 Precise collision detection systems
  • 🌟 Special effects and animations
  • 🏆 Level design best practices

📚 Related Tutorials

Ready to build amazing platformers? Get expert guidance from our tutors!