Unity Raycast, TimeScale, GetAxis and isKinematic

本文详细介绍了Unity中与游戏物理交互相关的几个关键概念:Raycast用于检测碰撞的函数;Time.timeScale如何控制游戏时间流逝速度,包括对FixedUpdate的影响;Input.GetAxis用于获取输入轴值的方法,提供帧率独立的输入响应;以及Rigidbody.isKinematic属性,用于切换刚体的动态与静态状态,影响物理引擎对其的处理方式。
摘要由CSDN通过智能技术生成

Raycast

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

Parameters

originThe starting point of the ray in world coordinates.
directionThe direction of the ray.
hitInfoIf true is returned, hitInfo will contain more information about where the collider was hit. (See Also: RaycastHit).
maxDistanceThe max distance the ray should check for collisions.
layerMaskLayer mask that is used to selectively ignore colliders when casting a ray.
queryTriggerInteractionSpecifies 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

barycentricCoordinateThe barycentric coordinate of the triangle we hit.
colliderThe Collider that was hit.
distanceThe distance from the ray's origin to the impact point.
lightmapCoordThe uv lightmap coordinate at the impact point.
normalThe normal of the surface the ray hit.
pointThe impact point in world space where the ray hit the collider.
rigidbodyThe Rigidbody of the collider that was hit. If the collider is not attached to a rigidbody then it is null.
textureCoordThe uv texture coordinate at the collision location.
textureCoord2The secondary uv texture coordinate at the impact point.
transformThe Transform of the rigidbody or collider that was hit.
triangleIndexThe 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值