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

Is there a way to define Angle (0,0,0) for a part?

A little background, I'm trying to make a 3-Dimentional radar; I'm using a local part, a sphere which I negated the center and sections of so it's kind of wireframe. When the player tilts forward, I want the sphere, no matter what orientation it's in, to tilt forward from the player; if that makes sense. This is what I currently have:

Also, I have FilteringEnabled, so this is a local part; no one else can see it.

local plr = game.Players.LocalPlayer
local ship = plr.Character:WaitForChild("Plane")
local engine = ship.Parts.Engine
local radar = script.Parent.Radar

if ship.Parts:FindFirstChild("RadarPoint") == nil or game.Workspace.FilteringEnabled == false then
	script:remove()
end

radar.Parent = game.Workspace
radar.Anchored = true

local lastx, lasty, lastz = 0,0,0
local deltaxtotal, deltaytotal, deltaztotal = 0,0,0
function updateRadar()
	local x,y,z = engine.CFrame:toEulerAnglesXYZ()
	local deltax, deltay, deltaz = x-lastx, y-lasty, z-lastz
	
	deltaxtotal, deltaytotal, deltaztotal = deltaxtotal+deltax, deltaytotal+deltay, deltaztotal+deltaz
	
	local position = ship.Parts.RadarPoint.CFrame
	radar.CFrame = position * CFrame.Angles(deltaxtotal, deltaytotal, deltaztotal)
	
	lastx, lasty, lastz = x,y,z
end

game:GetService("RunService").RenderStepped:connect(updateRadar)

It doesn't do what I want; it actually acts as a gyro, identifiying the orientation compared to 0,0,0.

I can think of two ways to achieve my goal.

  1. Figure out the trig required to alter all of the CFrame angles so that it does what I want(I can deal with this if I have to, I would just prefer to not if possible)

  2. Reset the CFrame angles of the object to be 0,0,0 each time through but keep the orientation of the object. Is that possible? Edit: To be more clear, I want to be able to rotate the block based a specific coords and rotation, not based on the world coords and rotation. I.e. Rotate it so that, if I rotate on an axis, it always rotates the same direction relative to a different block.

1 answer

Please, try this. You need to reset the CFrame every time..


local plr = game.Players.LocalPlayer

local ship = plr.Character:WaitForChild("Plane")

local engine = ship.Parts.Engine

local radar = script.Parent.Radar

if ship.Parts:FindFirstChild("RadarPoint") == nil or game.Workspace.FilteringEnabled == false then

    script:remove()
end

radar.Parent = game.Workspace

radar.Anchored = true

local lastx, lasty, lastz = 0,0,0

local deltaxtotal, deltaytotal, deltaztotal = 0,0,0

function updateRadar()

    local x,y,z = engine.CFrame:toEulerAnglesXYZ()

    local deltax, deltay, deltaz = x-lastx, y-lasty, z-lastz

    deltaxtotal, deltaytotal, deltaztotal = deltaxtotal+deltax, deltaytotal+deltay, deltaztotal+deltaz

    local position = ship.Parts.RadarPoint.Position

    radar.CFrame = CFrame.new(position)* CFrame.Angles(deltaxtotal, deltaytotal, deltaztotal)

    lastx, lasty, lastz = x,y,z

end

game:GetService("RunService").RenderStepped:connect(updateRadar)

1 comment

0

That is not correct, and, while it resets the CFrame each time, it doesn't do what I asked. I want to reset the CFrame, but keep the current orientation of the block. Essentially, say that, whatever the block's current rotation is is now 0,0,0

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