如何从它们之间的两个向量3中提取一个值(z)?

问题描述 投票:0回答:1

更清楚地说,我想让某个向量3的Z值减去另一个向量3的Z值,只有Z一个,这样使得第一个向量3的X和Y值保持不变,而唯一的修改为Z

这些是具体的线路。如果这些行不代表实际的 vector3 值,或者我犯了一个我没有注意到的错误,请告诉我。

local direction = (endPosition - startPosition).Unit * range --I want to subtract the Z value of this vector3...

    if raycast then
       local sth = raycast.Instance.Position --...with the Z value of this other one...
       local mod = vector3(Xdirval, Ydirval, Zmodval) --...and create this supossed new vector3, with the X and Y values of the "direction"'s vector3.
    end

我已经学会了如何获取向量3的具体值(在本例中为Z),但我不知道如何在两者之间执行算术并将其放入新的向量3中,也不知道如何提取项目的向量3我需要(某事和方向)

vector lua roblox
1个回答
0
投票

只需唤起您想要使用的矢量位置即可。

如果你有两个向量:

coord1 = vector3(11, 2, 0)
coord2 = vector3(1, 1, 1)

您可以进行如下数学运算

print(coord1.x - coord2.x)
>>10
© www.soinside.com 2019 - 2024. All rights reserved.