@rbxts/replace
v1.0.1
Published
Helping library implements simpler way working with roblox vectors & cframes
Readme
💞 Replace
Helping library implements simpler way working with roblox vectors & cframes
pronounced as re-place
⚙️ Credits
sumer_real
📦 Install
npm install @rbxts/replace
🍴 Cookbook
smooth cyclic rotation
const ROTATION_ANGLE_PER_SECOND = 30
const target = Workspace.WaitForChild("ObjectToRotate") as BasePart;
RunService.Heartbeat.Connect((delta) => {
target.CFrame = replace(target.CFrame)
.rotateY(ROTATION_ANGLE_PER_SECOND * delta)
.toCFrame();
});simple pet system
const pet = Workspace.WaitForChild("Pet") as BasePart;
const player = Players.LocalPlayer;
RunService.Heartbeat.Connect((delta) => {
if (!player.Character) return;
if (!player.Character.PrimaryPart) return;
pet.CFrame = replace(player.Character.GetPivot())
.backward(4)
.inverseLerp(pet.CFrame, delta / 0.075)
.toCFrame();
});📚 Documentation
To start using this library, we need to study all types of operations, there are 4 of them
📐 absolute
These operations are independent of related cframe
position(x, y, z)updates positionangle(xDeg, yDeg, zDeg, xRad?, yRad?, zRad?)updates anglelerp(target: CFrame, alpha)lerps replace to target by alphainverseLerp(from: CFrame, alpha)lerps target to replace by alpha
🧷 relative
operations of this type depend entirely on related cframe
move(x, y, z)moves position by value considering the anglerotate(xDeg, yDeg, zDeg, xRad?, yRad?, zRad?)rotates angle considering current angleforward(value)moves position forwardbackward(value)moves position backwardleft(value)moves position leftright(value)moves position rightup(value)moves position updown(value)moves position downrotateX(deg, rad?)rotates x by math.rad(deg) + radrotateY(deg, rad?)rotates y by math.rad(deg) + radrotateZ(deg, rad?)rotates z by math.rad(deg) + rad
⚖️ switch
allows you to change the logic of relativity
world()converts current position & angle to world spacerelative(to: CFrame)Replace will assume that position and angle intospaceasRelative(to: CFrame)will convert position & angle from world totospace
✉️ finaliters
operations of this type allow you to convert replace back to roblox formats
the main purpose of this library is to simplify CFrame, not Vector3, so it is more difficult to work with them.
toCFrame()will convert to CFrame, recommended finalitertoVector3()will convert to Vector3 be careful, it doesn't take into account the angle, only relative operations related to move are taken into accounttoRotatedVector3()will convert to Vector3, but this operation takes into account angle, be careful don't use move related operations before this operation
