Skip to main content

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)
ParameterTypeDescription
pos1Vector3Origin position
pos2Vector3Target position
forwardVector3Fallback 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).Unit directly.
  • The fallback forward is not normalised automatically — pass a unit vector.