Convert negatives within vector to positive

  1. What do you want to achieve?

I have a vector value, which occasionally gets negative values, but the thing I want to use the vector for doesn’t support negatives. I want to convert these negative values to positive while keeping it in the vector format

  1. What is the issue?

I am not sure what method I need to use this

  1. What solutions have you tried so far?

I have tried searching for this online and I guess I could use math.abs() on each individual axis. Is there a way to apply this to the vector all at once?

local abs = math.abs
local function convert(vec3)
    return Vector3.new(abs(vec3.x), abs(vec3.y), abs(vec3.z)
end

This gets the absolute value of each component of the Vector, making them positive.

2 Likes