# Player Collision Behavior with Buildings in Castle Game Engine

**URL:** https://forum.castle-engine.io/t/player-collision-behavior-with-buildings-in-castle-game-engine/2128
**Category:** 3D
**Created:** [March 8, 2026, 12:08pm UTC](https://forum.castle-engine.io/t/player-collision-behavior-with-buildings-in-castle-game-engine/2128 "2026-03-08T12:08:04Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Hamid](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/hamid/32/2741_2.png) [@Hamid](https://forum.castle-engine.io/u/Hamid)
#### Post date: [March 8, 2026, 12:08pm UTC](https://forum.castle-engine.io/t/player-collision-behavior-with-buildings-in-castle-game-engine/2128/1 "2026-03-08T12:08:04Z")

</div>

I used **TCastleCapsuleCollider** for the player and **TCastleBoxCollider** for the ground and buildings.  
I also added **TCastleRigidBody** to all of them.  
For the Body, I set **Dynamic** to **False**.  
For all of them, I set the following values:

```auto
Scene.Collides := True;
Scene.PreciseCollisions := True;

```

When the player collides with a building, they can only move in the opposite direction and cannot move in other directions.  
For the player, there is a mechanism to rotate toward the clicked position.

---

<div class="post-metadata">

### Author: ![Hamid](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/hamid/32/2741_2.png) [@Hamid](https://forum.castle-engine.io/u/Hamid)
#### Post date: [March 8, 2026, 4:39pm UTC](https://forum.castle-engine.io/t/player-collision-behavior-with-buildings-in-castle-game-engine/2128/2 "2026-03-08T16:39:54Z")

</div>

I have also used `ViewportPlay.Items.WorldRayCast(RayOrigin, RayDir, Dist);` for now and calculate the collision. This way, it works much better.

---

<div class="post-metadata">

### Author: ![kagamma](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/kagamma/32/226_2.png) [@kagamma](https://forum.castle-engine.io/u/kagamma)
#### Post date: [March 9, 2026, 2:50am UTC](https://forum.castle-engine.io/t/player-collision-behavior-with-buildings-in-castle-game-engine/2128/3 "2026-03-09T02:50:03Z")

</div>

IMO since your game is grid-based, it is much easier to handle collision using the grid rather than relying on physics engine.

---

<div class="post-metadata">

### Author: ![Hamid](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/hamid/32/2741_2.png) [@Hamid](https://forum.castle-engine.io/u/Hamid)
#### Post date: [March 10, 2026, 7:36am UTC](https://forum.castle-engine.io/t/player-collision-behavior-with-buildings-in-castle-game-engine/2128/4 "2026-03-10T07:36:18Z")

</div>

Yes, my ground is represented as a matrix. However, the other objects placed on the ground are created as a dynamically sized array (to save memory).

---

<div class="post-metadata">

### Author: ![phomm](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/phomm/32/2827_2.png) [@phomm](https://forum.castle-engine.io/u/phomm)
#### Post date: [March 10, 2026, 3:27pm UTC](https://forum.castle-engine.io/t/player-collision-behavior-with-buildings-in-castle-game-engine/2128/5 "2026-03-10T15:27:37Z")

</div>

@Hamid , Kagamma meant, that if you have game rules and characters tied to the discrete grid and cannot be placed in linear/non-discrete space (like between tiles), you don’t actually need to use physics to check for collisions. Because you can check if characters “collide” when they step on the occupied tile just by grid/arrays of characters check.

For example, in my 3d game all characters are placed strictly on tiles (logically , by game rules) and all checks are made inside game rules. Only for visual coherence I make them gradually move from tile to tile by simple Lerp/delta approach
