yo
i have the solution to ur problem
basically all you have to do is switch the x and y components of your mouse unit vector
yo
i have the solution to ur problem
basically all you have to do is switch the x and y components of your mouse unit vector
I think this should be
if degrees < 0 then -- to account for your -1 to -180 value
degrees = 180 - degrees -- for example if it's -20 then 180 - -20 = 200
end
degrees = degrees - 90 -- to rotate it to the vertical position
I haven’t worked with UIs so I’m not exactly sure if this would work, but give it a try.
@ghostreperlord does that work for a UI though?
well it should because if you switch the .x and .y then you get a vector 90 degrees to the first
so basically all the results will be as if u turned it 90 degrees around which is what he wants :3
glad it wasnt 30 degrees or something cause im pretty sure we would need rotation matrices for that ;-;
OP I think you just need to offset your angle calculation by -90.
And then you can add some clauses to ensure your calculations add up well.
local angle = blahblah
angle -= 90
if angle >= 360 then
angle -= 360
elseif angle < 0 then
angle += 360
end
No you wouldn’t.
OP I would like you to keep in mind that the angles internally can be different and since its just a simple offset you can just manipulate what’s being displayed as that would be easier than completely changing your calculations.
close but it goes negative, like 1 - 270 and then negative
oh fair enough i overcomplicated things, but my solution should work too
OP I would like you to keep in mind that the angles internally can be different and since its just a simple offset you can just manipulate what’s being displayed as that would be easier than completely changing your calculations.
honestly i think that would be harder because i already have the code for my weapon wheel but just doing what you said would make me rewrite alot of the code
if i could just do what im trying to do itd be easier and fix it instantly
i have no idea how to replace the x and y
Apologize but I don’t get how a simple offset is going to make you need to rewrite your code. Can you show how you are calculating the angle so we can help you?
just replace the x coordinate for the mouse with the y and the y with the x
for i, v in ipairs(self.slots) do
if Degrees <= i * degPerSegment then
print(`selecting {i}`)
break
end
end
right now if i hover my mouse to the top it will say “selecting 3” (total of 8 slots). which i dont want because i want the first slot to be the empty slot where you unequip, now slot 1 is towards the right (where I dont want it to be)
if i just change the way its calculated then me moving my mouse at top will make it select slot 1 instead of 3
local RelativeDirection = (getPosition() - self.UI.CoordinateSystem.AbsolutePosition).Unit
local Degrees = math.deg(math.acos(RelativeDirection.X))
if math.sign(RelativeDirection.Y) == 1 then
Degrees = 360 - Degrees
end
self.UI.DisplayVector.Arrow.Position = UDim2.new(0, 50*RelativeDirection.X, 0, 50*RelativeDirection.Y) + self.UI.CoordinateSystem.Position
self.UI.DisplayVector.Arrow.Rotation = -Degrees
local degPerSegment = 360 / 8
for i, v in ipairs(self.slots) do
if Degrees <= i * degPerSegment then
print(`selecting {i}`)
break
end
end
print(Degrees)
well idk imo what i would do here is get
`
local mousePos = getPosition()
local newPos = Vector2.new(mousePos.Y,mousePos.X)
local RelativeDirection = (newPos - self.UI.CoordinateSystem.AbsolutePosition).Unit
local Degrees = math.deg(math.acos(RelativeDirection.X))
if math.sign(RelativeDirection.Y) == 1 then
Degrees = 360 - Degrees
end
self.UI.DisplayVector.Arrow.Position = UDim2.new(0, 50*RelativeDirection.X, 0, 50*RelativeDirection.Y) + self.UI.CoordinateSystem.Position
self.UI.DisplayVector.Arrow.Rotation = -Degrees
local degPerSegment = 360 / 8
for i, v in ipairs(self.slots) do
if Degrees <= i * degPerSegment then
print(`selecting {i}`)
break
end
end
print(Degrees)`
Exactly.
Why not just compute the “DegreesToDisplay” value from here using the method I suggested. This is what I meant when I said you don’t have to change how you calculate it but change what you show. All you need to do is show the user what he needs to see while you can retain your internal code.
yeah what im trying to say it would be easier to change the calcuation rather than what im showing
wait what? why cant you just calculate another value for the gui text? just change the gui value thats what im saying.
Try:
if degrees < 0 then -- to account for your -1 to -180 value
degrees = 180 - degrees -- for example if it's -20 then 180 - -20 = 200
end
if degrees < 270 then
degrees = degrees - 90 -- to rotate it to the vertical position
else
degrees = 360 - degrees -- or 270 + degrees, my brain is fried right now
end
it didnt work
What do you get with that script instead of 1 to 270 then negative numbers?