Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to teleport character 45* degrees?

Asked by
noammao 294 Moderation Voter
6 years ago

I want to make my character teleport 45* degrees of where the character is looking, assuming I'm in first person. I've tried to use rightvector and lookvector but I don't know how to get the 45-degree angle.

0
"teleport 45* degrees of where the character is looking" makes no sense. cabbler 1942 — 6y
0
Yes it does. 0 or 360 degrees are forward. 90 is on your right. 180 is backwards and 170 is left. so 45 degrees would be somewhere in the middle between forward and right. What I am trying to do is that when you press down W and D you dont teleport forward or to the right, you teleport somewhere in between. Am I being mroe clear now? noammao 294 — 6y

3 answers

Log in to vote
2
Answered by
cabbler 1942 Moderation Voter
6 years ago

So I assume you're confused how to get the proper direction. No cframe has a stock 45 degrees vector. You can easily get there with the lookvector of [that cframe offset by a 45deg cframe].

  • CFrame.Angles() returns a cframe with no position but rotated with the given radian angles. The radian angle you want is math.pi/-4. Y value spins vertically. CFrame.Angles(0,math.pi/-4,0)

  • Offset the original's rotation by 'multiplying' this. Then you have a useful direction: (cf*CFrame.Angles(0,math.pi/-4,0)).lookVector

  • Then of course multiply it by a distance, add to the original. hope you get it!

local char = game.Players.LocalPlayer.Character
local ppartcf = char.PrimaryPart.CFrame
local new = ppartcf+(ppartcf*CFrame.Angles(0,math.pi/-4,0)).lookVector*5
char:SetPrimaryPartCFrame(new)
0
That was exactly what I ment! Thank you so much bro! You are a god!!! noammao 294 — 6y
Ad
Log in to vote
0
Answered by
Nowaha 459 Moderation Voter
6 years ago
Edited 6 years ago
Log in to vote
0
Answered by 6 years ago
local plr = game.Players.LocalPlayer
repeat wait() until plr.Character
local char = plr.Character
char:SetPrimaryPartCFrame(char.PrimaryPart.CFrame * CFrame.Angles(math.rad(45),0,0))

0
Didnt work. My character just bugs in place. I'm not trying to rotate my character. only make it dash in a direction. https://youtu.be/iW0eIaqiVdQ noammao 294 — 6y

Answer this question