TheLawMaster
TheLawMaster

Reputation: 1

How do i just use y position for cframe on roblox

I wanted to just use y position instead of the x,y,z positions. Here's my code

My Code That I needed Help On

Upvotes: 0

Views: 2768

Answers (2)

Do you mean your wanting to get the y position of the object or only move it on the y property here are examples of both

ypos = part.Position.Y

or

part.CFrame = CFrame.new(part.CFrame.X,part.CFrame.Y,part.CFrame.Z)

for the second one leave everything the same but change the y value you can also move it from its current y value by leaving it all the same and on the part.CFrame.Y part of the code just add +1 or however much you want to move it by right after y hope this helps if not then im not understanding the question clearly

Upvotes: 0

Ravenshield
Ravenshield

Reputation: 133

There's no way to just edit the Y-value alone, but you can append a new vector to your current vector, or recreate your vector with some of the old components.

Example:

local Position = Vector3.new(12, 5, 9)
local newPosition = Position + Vector3.new(0, 10, 0)
print(newPosition) -- prints (12, 15, 9)

The principle is the same for CFrames. You can also add a vector to a CFrame, if you just need clean movement on world axis.

local myCf = CFrame.new(12, 5, 9, ...) -- some CFrame, '...' corresponding to the CFrame-components for rotation.
local newCf = myCf + Vector3.new(0, 10, 0)
print(newCf) -- prints (12, 15, 9, ...)

Alternatively you can recreate your Vector/CFrame with existing components

local Position = Vector3.new(12, 5, 9)
local newPosition = Vector3.new(Position.X, 15, Position.Z)

Upvotes: 1

Related Questions