[英]how to remove inertia unity3d
我有一個可以跳上梯子的球,但是當跳躍結束時,球仍然移動了一小段距離。 它曾經長途旅行,我只是設置了 freezeRotation = true,但慣性仍然存在。 我很樂意提供任何建議。 這是我的代碼
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class ballcontroller : MonoBehaviour
{
//public int speed = 3;
public int jumpForce;
public bool IsGround;
private Rigidbody rb;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
private void Update()
{
//float Vm = Input.GetAxis("Vertical");
//float Hm = Input.GetAxis("Horizontal");
//Vector3 V3M = new Vector3(Hm, 0, Vm);
//rb.AddForce(V3M * speed);
Jump();
}
public void Jump()
{
Ray ray = new Ray(gameObject.transform.position, Vector3.down);
RaycastHit rh;
if (Physics.Raycast(ray, out rh, 0.5f))
{
IsGround = true;
}
else
{
IsGround = false;
}
if (Input.GetKeyDown(KeyCode.Space) && IsGround)
{
rb.AddForce(Vector3.one * jumpForce);
rb.freezeRotation = true;
}
}
}
您可以使用Rigidbody.velocity
和Rigidbory.angularVelocity
直接操縱剛體的速度。 您可以在Vector3.zero
其設置為Vector3.zero
(或緩慢減小以防止硬凍結)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.