using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TankMovement : MonoBehaviour {
public float moveSpeed = 5; //移动速度
public float angularSpeed = 10; //旋转角度
private Rigidbody thisRigidbody; //刚体
void Start()
{
thisRigidbody = this.GetComponent<Rigidbody>();
}
void FixedUpdate()
{
//方向*输入*速度
float v = Input.GetAxis("VerticalPlayer" + number);
thisRigidbody.velocity = transform.forward * v * moveSpeed;
float h = Input.GetAxis("HorizontalPlayer" + number);
thisRigidbody.angularVelocity = transform.up * h * angularSpeed;
}
}
using System.Collections.Generic;
using UnityEngine;
public class TankMovement : MonoBehaviour {
public float moveSpeed = 5; //移动速度
public float angularSpeed = 10; //旋转角度
private Rigidbody thisRigidbody; //刚体
void Start()
{
thisRigidbody = this.GetComponent<Rigidbody>();
}
void FixedUpdate()
{
//方向*输入*速度
float v = Input.GetAxis("VerticalPlayer" + number);
thisRigidbody.velocity = transform.forward * v * moveSpeed;
float h = Input.GetAxis("HorizontalPlayer" + number);
thisRigidbody.angularVelocity = transform.up * h * angularSpeed;
}
}
本文介绍了一个简单的Unity坦克移动脚本,通过控制坦克的速度和旋转角度实现玩家操控。使用刚体组件进行物理模拟,并通过获取玩家输入来改变坦克的前进方向和旋转状态。

被折叠的 条评论
为什么被折叠?



