Hey, It’s Army back with I think the 3rd post of the day?
Anyway, today I’m here because my LookVector Isn’t working. I’ve been working on a project that involves an attack, and I’m creating sort of a knockback. I’ve finally gotten the player to be knocked back, now I just need them to be knocked back in the opposite direction they’re looking at.
The full script isn’t needed, so Imma just post the related script:
local LocalPlayer = game.Players.LocalPlayer
local Character = game.Workspace:WaitForChild(LocalPlayer.Name)
local Hum = Character:WaitForChild("Humanoid")
local PrimaryPart = Character.PrimaryPart
--Bunch of code that doesnt really have anything to do with this
local TweenOutcome1 = {
CFrame = PrimaryPart.CFrame * PrimaryPart.LookVector * CFrame.new(0, 0, 10)
}
However, It says that LookVector Isn’t part of the PrimaryPart, can someone help? Thank you!
LookVector
is a property of CFrames.
Also I believe you are trying to scale the look vector by 10, not offset it by 10?
Perhaps you are looking to do this:
local TweenOutcome1 = {
CFrame = PrimaryPart.CFrame + PrimaryPart.CFrame.LookVector * 10
}
But it might be better said to do this:
local TweenOutcome1 = {
CFrame = PrimaryPart.CFrame * CFrame.new(0, 0, 10)
}
What does scaling the lookvector do?
P.S. I edited my original post a bit
It just scales it? When you multiply a number to a Vector it will multiply all of those values by that value.
Vector3.new(1, 2, 3) * 2 == Vector3.new(1 * 2, 2 * 2, 3 * 2) == Vector3.new(2, 4, 6)
When you scale the LookVector of a part by N
and then offset the Part’s CFrame by that scaled LookVector, then you will shift the part N
studs forwards.
Well, the reason I wanted to use LookVector was because I wanted to take the Characters Position in mind when moving it.
And thanks for the info, it helped a lot!
You can just offset the CFrame directly, because a CFrame is a position and a rotation.
part.CFrame = part.CFrame * CFrame.new(0, 0, 10)
would shift a part 10
studs forward in the direction of the part’s look vector (also known as the part’s face)
1 Like
I got an error saying “TweenService:Create property named ‘CFrame’ cannot be tweened due to type mismatch (property is a ‘CoordinateFrame’, but given type is ‘Vector3’)” What does this mean?
Can you show the code?
It means the statement evaluated to a Vector3 instead of a CFrame, but you defined the property as going to be a CFrame.
Its like if you said this (and this is bad):
local TweenOutcome1 = {
CFrame = Vector3.new(1, 2, 3)
}
Hmm, don’t think I did.
local LocalPlayer = game.Players.LocalPlayer
local Character = game.Workspace:WaitForChild(LocalPlayer.Name)
local Hum = Character:WaitForChild("Humanoid")
local PrimaryPart = Character.PrimaryPart
local TweenService = game:GetService("TweenService")
local Animation = Hum:LoadAnimation(script:WaitForChild("Animation"))
wait(3)
Animation:Play()
wait(2)
local TweenInfo1 = TweenInfo.new(
1,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
false,
0
)
local TweenOutcome1 = {
CFrame = PrimaryPart.CFrame * PrimaryPart.CFrame.LookVector * 10
}
local MoveCharacter = TweenService:Create(PrimaryPart, TweenInfo1, TweenOutcome1)
MoveCharacter:Play()
Try
CFrame = PrimaryPart.CFrame + PrimaryPart.CFrame.LookVector * 10
or
CFrame = PrimaryPart.CFrame * CFrame.new(0, 0, 10)
Using the regular one gave me an error, somthing about not being able to teleport. However, setting the 10 to -10 (because I wanted to the character to get knocked backwards) made the error go away for some reason.
This gave me the same result, but roblox still gave me the error on teleporting. Whats the deal with the error?
Hello? Are you here or did I answer too late?