在2D Unity中,AddForce transform.forward不起作用的原因是,transform.forward是基于3D空间的概念,它表示物体当前朝向的向量。在2D场景中,物体只能在平面上移动,没有朝向的概念,因此使用transform.forward来施加力量是无效的。 要在2D Unity中实现物体的移动,可以使用Rigidbody2D组件和AddForce方法的另一种方式。...
if(Mathf.Abs(GetComponent<Rigidbody2D>().velocity.x) > maxSpeed)GetComponent<Rigidbody2D>().velocity = new Vector2(Mathf.Sign(GetComponent<Rigidbody2D>().velocity.x) * maxSpeed, GetComponent<Rigidbody2D>().velocity.y);就可以了。
【小白求教】为什么不../*1、 这个脚本所携带的物体的 2D刚体组件。施加力 gameObject.GetComponent<Rigidbody2D>().AddForce(transform
void StopMove(){ //2D gameObject.GetComponent<Rigidbody2D>().isKinematic = true;//3D gameObject.GetComponent<Rigidbody>().isKinematic = true;}
public voidAddForce(Vector2force,ForceMode2Dmode= ForceMode2D.Force); Parameters forceComponents of the force in the X and Y axes. modeThe method used to apply the specified force. Description Apply a force to the rigidbody. The force is specified as two separate components in the X and Y...
如果希望拍子与周围的长方体发生碰撞,则应使用AddForce()移动刚体,而不是移动变换。或者,您可以像...
C#=> void AddForce(Vector2force,ForceMode2Dmode = ForceMode2D.Force); Parameters 参数 forceComponents of the force in the X and Y axes. 在X和Y轴的力的组件。 modeThe method used to apply the specified force. 该方法用于应用指定的力。
rb.AddForce(new Vector2(-inputDirection.x,2f) * wallJumpForce, ForceMode2D.Impulse); } 蹬墙跳出后立即回墙的问题 由于跳出后依旧再按住方向键,因此,跳出后会立即回来 新建一个wallJump状态,修改人物移动逻辑 // 人物移动if(isCrouch) { rb.velocity =newVector2(0.0f,0.0f); ...
Force Add a force to the Rigidbody2D, using its mass. Impulse Add an instant force impulse to the rigidbody2D, using its mass. Did you find this page useful? Please give it a rating: Report a problem on this page Is something described here not working as you expect it to? It mig...
You can click it at any time to pop in and out of 2D working mode. A 2D game in Unity is really still a 3D environment; your work is just constrained to the X and Y axes. Figure 1 and Figure 2 show the 2D mode selected and not selected. I have the camera highlighted so you ...