Skip to content

Commit c96a8e8

Browse files
fix(raycast): Offset grapple raycast origin
The raycast for the grappling hook was originating from the center of the player's physics body. This caused issues when the player was very close to a grapple anchor, as the ray's origin could be inside the anchor's physics volume, preventing the raycast from detecting it. This change offsets the starting point of the raycast by 2 units in the direction the player is looking. This ensures that the raycast always begins from a point in front of the player, allowing it to correctly detect anchors even when the player is standing right next to them.
1 parent 675a338 commit c96a8e8

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

cave-game/server/entities/PlayerEntity.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,10 @@ export class PlayerEntity extends Entity {
189189
lastFoundAnchor: GrappleAnchorEntity | null = null;
190190
lastAnchor: GrappleAnchorEntity | null = null;
191191
findGrappleAnchor(lookDir: YXZEuler): GrappleAnchorEntity | null {
192+
const dir = new phys.Vec3(-Math.sin(lookDir.y), Math.sin(lookDir.x), -Math.cos(lookDir.y)).unit();
192193
const objects = this.game.raycast(
193-
this.body.position,
194-
new phys.Vec3(-Math.sin(lookDir.y), Math.sin(lookDir.x), -Math.cos(lookDir.y))
195-
.unit()
196-
.scale(100)
197-
.vadd(this.body.position),
194+
this.body.position.vadd(dir.clone().scale(2)), // start the ray 2 units in front of the player
195+
dir.scale(100).vadd(this.body.position),
198196
{},
199197
this,
200198
);

0 commit comments

Comments
 (0)