Is it possible to add/subtract the position value of a specific axis?
For example if a part has the Position of 0,0,0 how would it be possible to add to the x axis with a script so that the final position would be 5,0,0?
(Apologies if this doesn’t make much sense, it’s difficult to put it into words)
1 Like
P1X3L_K1NG
(P1X3LK1NG)
2
-- example
local pos = Vector3.new(0, 0, 0)
pos += Vector3.new(5, 0, 0)
print(pos) --> 5, 0, 0
1 Like
ItsSovxy
(Sovxy)
3
Yes this is very simple all you will need to do is get the Vector’s dimension axis and by using the operator += you can simply add on to the old val.
1 Like
Would it be possible to get the value of a specific axis? For example getting the value to the Y Axis?
1 Like
P1X3L_K1NG
(P1X3LK1NG)
5
local pos = Vector3.new(0, 0, 0)
-- pos.X / pos.Y / pos.Z
1 Like
You can try
Vector3.new(0 + 5, 0, 0)
No idea if this works, but if it doesn’t work then try
pos = pos + Vector3.new(5,0,0)
P1X3L_K1NG
(P1X3LK1NG)
7
Essentially does the exact same thing.
Is the equivalent of saying:
Vector3.new(5, 0, 0)
@CaptainWeetabix
To add to a specific axis of a Vector3, you would simply add another Vector3 where only one axis is being added:
local pos = Vector3.new(0, 0, 0)
pos += Vector3.new(5, 0, 0)
print(pos) --> 5, 0, 0
When adding Vector3s together, each axis of each Vector3 will be added together, returning a new Vector3:
x y z
-------------------------------
Vector3.new ( 0 0 0 )
+ + +
Vector3.new ( 5 0 0 )
-------------------------------
result: ( 5 0 0 )
So to add only to the X axis of your Vector3, you would need to add Vector3.new(your_increment_here, 0, 0) to the current Vector3.
Vector3 API and math operations
2 Likes