Pulse.Vec
Pulse.Vec provides small vector helpers that come up repeatedly in combat and movement features.
Pulse.Vec.flatDir
Returns a normalised horizontal (XZ-plane) direction vector from pos1 toward pos2. If pos1 and pos2 are at the same XZ position the fallback forward vector is returned instead.
local direction = Pulse.Vec.flatDir(myHRP.Position, targetHRP.Position,
Vector3.new(myHRP.CFrame.LookVector.X, 0, myHRP.CFrame.LookVector.Z).Unit)
| Parameter | Type | Description |
|---|---|---|
pos1 | Vector3 | Origin position |
pos2 | Vector3 | Target position |
forward | Vector3 | Fallback direction when pos1 == pos2 (XZ) |
Returns Vector3 — unit vector in the XZ plane pointing from pos1 to pos2.
The Y component is always 0. Use this when you want to kick or push a target in a direction without any vertical component (which would otherwise launch them into the air or into the floor).
TypeScript example
// src/combat/CombatKick.ts
on.heartbeat({ when: enabled }, () => {
const myRoot = _PulseGetHRP()
if (!myRoot) return
const nearest = Pulse.Aim.findNearest(func.GetCachedPlayers(), {
maxDist: range(),
getRoot: (p: Player) => p.Character?.FindFirstChild('HumanoidRootPart') as BasePart | undefined,
filter: (p: Player) => p !== _LocalPlayer && p.Character?.FindFirstChildWhichIsA('Humanoid') !== undefined,
})
if (!nearest || !_cd.ready(nearest)) return
_cd.use(nearest)
const targetRoot = (nearest as Player).Character!.FindFirstChild('HumanoidRootPart') as BasePart
const direction = Pulse.Vec.flatDir(
myRoot.Position,
targetRoot.Position,
new Vector3(myRoot.CFrame.LookVector.X, 0, myRoot.CFrame.LookVector.Z).Unit
)
pcall(() => Pulse.Remote.fire('Remotes/Gameplay/Kick', targetRoot.Parent!.FindFirstChildWhichIsA('Humanoid'), force(), direction))
})
Limitations
- Only handles XZ-plane directions. For full 3D directions, compute
(pos2 - pos1).Unitdirectly. - The fallback
forwardis not normalised automatically — pass a unit vector.