Unity Raycast, TimeScale, GetAxis and isKinematic

Raycast

public static bool Raycast(Vector3 origin, Vector3 direction, out RaycastHit hitInfo, float maxDistance, int layerMask, QueryTriggerInteractionqueryTriggerInteraction);

Parameters

origin The starting point of the ray in world coordinates.
direction The direction of the ray.
hitInfo If true is returned, hitInfo will contain more information about where the collider was hit. (See Also: RaycastHit).
maxDistance The max distance the ray should check for collisions.
layerMask Layer mask that is used to selectively ignore colliders when casting a ray.
queryTriggerInteraction Specifies whether this query should hit Triggers.

RaycastHit

struct in UnityEngine

Implemented in:UnityEngine.PhysicsModule

Other Versions

Leave feedback

Description

Structure used to get information back from a raycast.

See Also: Physics.RaycastPhysics.LinecastPhysics.RaycastAll.

Properties

barycentricCoordinate The barycentric coordinate of the triangle we hit.
collider The Collider that was hit.
distance The distance from the ray's origin to the impact point.
lightmapCoord The uv lightmap coordinate at the impact point.
normal The normal of the surface the ray hit.
point The impact point in world space where the ray hit the collider.
rigidbody The Rigidbody of the collider that was hit. If the collider is not attached to a rigidbody then it is null.
textureCoord The uv texture coordinate at the collision location.
textureCoord2 The secondary uv texture coordinate at the impact point.
transform The Transform of the rigidbody or collider that was hit.
triangleIndex The index of the triangle that was hit.

Time.timeScale

1:“timeScale不会影响Update和LateUpdate的执行速度”

2:“FixedUpdate是根据时间来的,所以timeScale只会影响FixedUpdate的速度”

Other Versions

Leave feedback

public static float timeScale;

Description

The scale at which the time is passing. This can be used for slow motion effects.

When timeScale is 1.0 the time is passing as fast as realtime. When timeScale is 0.5 the time is passing 2x slower than realtime.

When timeScale is set to zero the game is basically paused if all your functions are frame rate independent.

Except for realtimeSinceStartuptimeScale affects all the time and delta time measuring variables of the Time class.

If you lower timeScale it is recommended to also lower Time.fixedDeltaTime by the same amount.

FixedUpdate functions will not be called when timeScale is set to zero.

Input.GetAxis

Other Versions

Leave feedback

public static float GetAxis(string axisName);

Description

Returns the value of the virtual axis identified by axisName.

The value will be in the range -1...1 for keyboard and joystick input. If the axis is setup to be delta mouse movement, the mouse delta is multiplied by the axis sensitivity and the range is not -1...1.

This is frame-rate independent; you do not need to be concerned about varying frame-rates when using this value.

Rigidbody.isKinematic

Other Versions

Leave feedback

SWITCH TO MANUAL

public bool isKinematic;

Description

Controls whether physics affects the rigidbody.

If isKinematic is enabled, Forces, collisions or joints will not affect the rigidbody anymore. The rigidbody will be under full control of animation or script control by changing transform.position. Kinematic bodies also affect the motion of other rigidbodies through collisions or joints. Eg. can connect a kinematic rigidbody to a normal rigidbody with a joint and the rigidbody will be constrained with the motion of the kinematic body. Kinematic rigidbodies are also particularly useful for making characters which are normally driven by an animation, but on certain events can be quickly turned into a ragdoll by setting isKinematic to false.

猜你喜欢

转载自blog.csdn.net/qq_27012963/article/details/83782440