Vector2

Hiển Thị Bản Đã Lỗi Thời

*Nội dung này sẽ sớm có sẵn bằng ngôn ngữ bạn chọn.

The Vector2 data type represents a 2D value with direction and magnitude. Some applications include GUI elements and 2D mouse positions.

Math Operations

The following math operations are valid for the Vector2 data type:

OperationDescription
Vector2 + Vector2Produces a Vector2 with each component of the second added to the corresponding component of the first.
Vector2 - Vector2Produces a Vector2 with each component of the second subtracted from the corresponding component of the first.
Vector2 * Vector2Produces a Vector2 with each component of the second multiplied by the corresponding component of the first.
Vector2 / Vector2Produces a Vector2 with each component of the first divided by the corresponding component of the second.
Vector2 * numberProduces a Vector2 with each component multiplied by the number.
Vector2 / numberProduces a Vector2 with each component divided by the number.

Tóm Tắt

Người Tạo

Thuộc Tính

Phương Pháp

  • Returns the cross product of the two vectors.

  • Returns a new vector from the absolute values of the original's components.

  • Returns a new vector from the ceiling of the original's components.

  • Returns a new vector from the floor of the original's components.

  • Returns a new vector from the sign (-1, 0, or 1) of the original's components.

  • Angle(other : Vector2,isSigned : bool):number

    Returns the angle in radians between the two vectors.

  • Returns a scalar dot product of the two vectors.

  • Lerp(v : Vector2,alpha : number):Vector2

    Returns a Vector2 linearly interpolated between this Vector2 and the given goal by the given alpha.

  • Max(others... : Tuple):Vector2

    Returns a Vector2 with each component as the highest among the respective components of the provided Vector2 objects.

  • Min(others... : Tuple):Vector2

    Returns a Vector2 with each component as the lowest among the respective components of the provided Vector2 objects.

  • FuzzyEq(other : Vector2,epsilon : number):bool

    Returns true if the X and Y components of the other Vector2 are within epsilon units of each corresponding component of this Vector2.

Người Tạo

new

Tham Số

Thuộc Tính

A Vector2 with a magnitude of zero.

This API member is a constant, and must be accessed through the Vector2 global as opposed to an individual Vector2 object.


print(Vector2.zero) --> 0, 0

A Vector2 with a value of 1 on every axis.

This API member is a constant, and must be accessed through the Vector2 global as opposed to an individual Vector2 object.


print(Vector2.one) --> 1, 1

xAxis

A Vector2 with a value of 1 on the X axis.

This API member is a constant, and must be accessed through the Vector2 global as opposed to an individual Vector2 object.


print(Vector2.xAxis) --> 1, 0

yAxis

A Vector2 with a value of 1 on the Y axis.

This API member is a constant, and must be accessed through the Vector2 global as opposed to an individual Vector2 object.


print(Vector2.yAxis) --> 0, 1

The x-coordinate of the Vector2.

The y-coordinate of the Vector2.

Magnitude

The length of the Vector2.

A normalized copy of the Vector2.

Phương Pháp

Cross

Returns the cross product of the two vectors.

Tham Số

other: Vector2

Lợi Nhuận

Returns a new vector from the absolute values of the original's components. For example, a vector of (-2, 4) returns a vector of (2, 4).

Lợi Nhuận

Returns a new vector from the ceiling of the original's components. For example, a vector of (-2.6, 5.1) returns a vector of (-2, 6).

Lợi Nhuận

Floor

Returns a new vector from the floor of the original's components. For example, a vector of (-2.6, 5.1) returns a vector of (-3, 5).

Lợi Nhuận

Returns a new vector from the sign (-1, 0, or 1) of the original's components. For example, a vector of (-2.6, 5.1) returns a vector of (-1, 1).

Lợi Nhuận

Angle

Returns the angle in radians between the two vectors. Specify true for the optional isSigned boolean if you want a signed angle. By default, the method returns the absolute value. Signed angles are a negative when going clockwise. Values are in the range [0, pi] for absolute angles and [-pi, pi] for signed angles.

Tham Số

other: Vector2
isSigned: bool
Giá Trị Mặc Định: false

Lợi Nhuận

Returns a scalar dot product of the two vectors.

Tham Số

Lợi Nhuận

Returns a Vector2 linearly interpolated between this Vector2 and the given goal by the given alpha.

Tham Số

alpha: number

Lợi Nhuận

Returns a Vector2 with each component as the highest among the respective components of the provided Vector2 objects.


local a = Vector2.new(1, 2)
local b = Vector2.new(2, 1)
print(a:Max(b)) -- Vector2.new(2, 2)

Tham Số

others...: Tuple

Lợi Nhuận

Returns a Vector2 with each component as the lowest among the respective components of the provided Vector2 objects.


local a = Vector2.new(1, 2)
local b = Vector2.new(2, 1)
print(a:Min(b)) -- Vector2.new(1, 1)

Tham Số

others...: Tuple

Lợi Nhuận

FuzzyEq

Returns true if the X and Y components of the other Vector2 are within epsilon units of each corresponding component of this Vector2.

Tham Số

other: Vector2
epsilon: number
Giá Trị Mặc Định: 0.00001 (1e-5)

Lợi Nhuận

Phép Toán