在3D里,一个全新的实体添加了刚体,默认启用重力,会下坠,速度较快。我的游戏实体,装载了组件,默认启用重力,下坠速度却没有前者快了。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TankMove : MonoBehaviour
{
public Rigidbody A;//刚体组件
//public float Speed = 5;//游戏实体移动速度
public float number = 1;//游戏实体序号
public float jiaoSpeed = 3;//转向速度
void Start()
{
A = this.GetComponent<Rigidbody>();//从检查器拖拽上获取游戏对象,予之赋值使其在代码中可使用
}
void FixedUpdate()
{
float b = Input.GetAxis("VerticalP" + number);
//A.velocity = transform.forward * b * Speed;
float a = Input.GetAxis("HorizontalP"+number);
A.angularVelocity = transform.up * a * jiaoSpeed;
}
}
排查原因:在移动的脚本里有“public float speed = 5;”及下文有在使用的项目。只要注释掉,坠落速度就正常了。但是这样一来被注释掉的代码就无法发挥作用了。关于移动的代码我目前只会这一个,
求解决办法,或指路一个替代该移动内容的方案
A.velocity = transform.forward * b * Speed
这句是赋予物体向前移动,影响了下落
你可以把方向改为下方,给物体赋予一个下落速度,让他下落快一些