phy_col_normal_x

This read-only array returns the x component of the collision normal corresponding to the phy_collision_x array value.

For each contact point there is an associated contact normal (which is usually the same normal for all points of contact in the collision). This contact normal is a unit vector that points from one instance in the collision to another, and can be used, for example, to calculate the correct "push" direction to resolve collisions.

NOTE This variable is only available in the collision event of a physics-enabled instance.

NOTE This variable does not hold a real GML array, so you cannot run any array functions on it or serialise it (convert it to a string). The only operation you can run on it is accessing a value at an index, with the phy_col_normal_x[index] syntax.

 

语法:

phy_col_normal_x[index]

 

返回:

Real (or undefined if the instance doesn't have physics enabled)

 

例子:

Collision Event

repeat(5 + irandom(5))
{
    with (instance_create_layer(x, y, "Effects", obj_Debris))
    {
        physics_apply_local_impulse(0, 0, other.phy_col_normal_x[0], other.phy_col_normal_y[0]);
    }
}

The above code uses the contact normal to set the direction of movement for an instance created in the collision event between two physics-enabled instances.