Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I convert CFrame to Vector3?

So, I'm making a DBZ game, and I need to move a part along a ray or part. In order to draw this beam/part I need 2 Vector3 values, I've got the Handle of the tool and the Mouse.Hit (Which is CFrame)

Is there anyway to convert a CFrame to Vector3?

Scripts:

Local Script in a Tool

local Tool = script.Parent
local Mouse = game.Players.LocalPlayer:GetMouse()
local Player = game.Players.LocalPlayer
local Event = game.ReplicatedStorage.ToolEvent

script.Parent.Activated:connect(function()
	Event:FireServer('Ki Blast', Mouse.Hit, Tool.Handle)
end)

ServerController Script :

local Atk = require(script.Parent.Attacks.AttackGenerator)
local Attacks = require(script.Parent.Attacks.Attacks)
local Morphs = require(script.Parent.Transformations.Transformations)
local PService = require(script.Parent.PlayerService)
local Event = game.ReplicatedStorage.ToolEvent

Event.OnServerEvent:connect(function(Player, AtkName, Target, Handle)
	if AtkName == 'Ki Blast' then
		Atk.KiBlastStart(Player, Target, Handle)
		PService.Values[Player.Name].Charging = true
	elseif AtkName == 'Ki Beam' then
		
	elseif AtkName == 'Ki Beam Release' then
		
	end
end)

Attack Module Script

local Atk = {}
local AtkValues = require(script.Parent.Attacks)
local PService = require(script.Parent.Parent.PlayerService)
local PValues = PService.Values
local Parts = game.ReplicatedStorage.Parts
local Sounds = game.ReplicatedStorage.Sounds
local DS = game:GetService('Debris')

local DrawBeam = function(beamstart, beamend, clr, fadedelay, templatePart)
	local dis = (beamstart - beamend).magnitude
	local laser=templatePart:Clone()
	laser.BrickColor = clr
	laser.Size = Vector3.new(.1, .1, dis + .2)
	laser.CFrame = CFrame.new((beamend+beamstart)/2, beamstart) * CFrame.new(0, 0, - dis/2)
	laser.Parent = workspace
end

Atk.KiBlastStart = function(Player, Target, Handle)
	local Counter = 0
	local Orb = SphereSynthesizer(Player, Target, Handle, 0.35, 'Bright bluish green', Vector3.new(0,0,0), true, Enum.Material.Neon)
	repeat
		wait()
		Counter = Counter + 1
		Orb.Mesh.Scale = Vector3.new(Counter/2,Counter/2,Counter/2)
	until Counter > 10
	Counter = 0
	Atk.KiBlastLaunch(Player, Target, Handle, Counter, Orb)
	DS:AddItem(Orb, AtkValues.Ki['Ki Blast'].Range)
end

Atk.KiBlastLaunch = function(Player, Target, Handle, Size, Orb)
	DrawBeam(Handle.Position,Target, BrickColor.new('Really red'), 5, Parts.Cube)
	local Play = Sounds.KiBlast:Clone()
	Play.Parent = Orb
	Play:Play()
	Orb.Parent = workspace
	Orb.Anchored = false
	Orb.Velocity = Vector3.new(0,100,0)
	Orb.CanCollide = true
	wait(3)
	for i=5,20,0.5 do wait()
		Orb.Mesh.Scale = Vector3.new(i*5,i*5,i*5)
		Orb.Transparency = Orb.Transparency + 0.025
	end
end

1 answer

✓ Accepted answer

How to covert a CFrame to a Vector3

Every CFrame value has the property .p which will give you the Vector3 of the Position of the CFrame.

Example,

local x = CFrame.new(1,2,3)
print("CFrame = "..x)
local y = x.p
print("Vector3 = "..y)

Good Luck!

If I helped, please don't forget to accept my answer!

This discussion is preserved as it was. New answers, comments, and votes are closed.