feat(field): adjust player position when moving through touch portals - #531
Conversation
Modify portal teleportation logic to offset player position when the portal's action type is Touch. This prevents players from spawning exactly on the portal. The offset uses either a default block size or a custom front offset if specified.
WalkthroughThe Changes
Sequence Diagram(s)sequenceDiagram
participant Player
participant FieldManager
participant Portal
Player->>FieldManager: UsePortal(sourcePortal)
FieldManager->>Portal: Get destination portal
FieldManager->>FieldManager: Extract position and rotation
alt Portal action type is Touch
FieldManager->>FieldManager: Apply forward offset to position
end
FieldManager->>Player: Send portal move packet with adjusted position and rotation
Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs (1)
554-568: Good improvement to portal positioning logic.The implementation correctly applies an offset to prevent players from being placed exactly on Touch portals. The logic properly extracts position and rotation, applies the offset in the forward direction, and handles both default and custom offset values.
However, consider adding null safety checks and position validation:
Vector3 position = dstPortal.Position; Vector3 rotation = dstPortal.Rotation; -if (dstPortal.Value.ActionType is PortalActionType.Touch) { +if (dstPortal.Value?.ActionType is PortalActionType.Touch) { // add one blocks or use offset in the direction of front axis float offset = Constant.BlockSize; - if (dstPortal.Value.FrontOffset != 0) { + if (dstPortal.Value.FrontOffset != 0) { offset = dstPortal.Value.FrontOffset; } Vector3 forward = dstPortal.Transform.FrontAxis; position += forward * offset; + + // Validate the final position is within valid navigation mesh + if (!ValidPosition(position)) { + logger.Warning("Portal offset resulted in invalid position {Position} for portal {PortalId}", position, dstPortal.Value.Id); + position = dstPortal.Position; // Fallback to original position + } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build
- GitHub Check: build
🔇 Additional comments (1)
Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs (1)
30-30: LGTM: Required import for vector math operations.The new using statement is necessary for the vector math operations introduced in the UsePortal method changes.
Modify portal teleportation logic to offset player position when the
portal's action type is Touch. This prevents players from spawning
exactly on the portal. The offset uses either a default block size
or a custom front offset if specified.
Summary by CodeRabbit