c# - 尝试使用 C# 转换游戏对象统一的位置
问题描述
在尝试更改游戏对象的位置及其速度时,我需要一些帮助。我知道翻译游戏对象,但我不知道如何提高它的翻译速度。顺便说一句,我正在使用统一游戏引擎。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class lightning : MonoBehaviour
{
//This is lightning
private GameObject name;
// Start is called before the first frame update
void Start()
{
name=GameObject.Find("car");
}
// Update is called once per frame
void Update()
{
if (Input.Keydone("r")
door.transform.Translate(-Vector3.right * Time.deltaTime);
}
}
解决方案
听起来您在速度和加速度方面遇到了问题。
我添加了一个速度变量和一个加速度变量,这两个变量可以使物体随着时间的推移越来越快。
由于这是物理学,我建议您在游戏对象上使用刚体并操纵其速度或施加力(力 = 质量 * 加速度),因此通过添加力它会给对象一个加速度。
//This is lightning
private GameObject name;
private float speedFactor = 20;
private float accelearationFactor = 5;
// Start is called before the first frame update
void Start()
{
name=GameObject.Find("car");
}
// Update is called once per frame
void Update()
{
if (Input.Keydone("r") {
door.transform.Translate(-Vector3.right * speedFactor * Time.deltaTime);
speedFactor += accelearationFactor * Time.deltaTime;
}
}
推荐阅读
- python-3.x - Coral EdgeTPU PWM 输出低平均电压问题与伺服电机
- php - Laravel 路由缓存
- python - 将列表的第一个元素与列表中的其他第一个元素匹配
- java - 按下按钮时如何删除布局
- c#-4.0 - 为什么我们在嵌套的 foreach 循环中这样做?我无法理解我迷路了
- python - 如何在 python 脚本中运行 python 脚本
- python - 如何使用python在列表中逐行插入字符串
- arduino - Arduino / DigiSpark / ATtiny85 - 接收和解析多条数据
- java - ArrayList 对象如何存储在 Java 中的 HashSet 中?
- openssl - 为什么 openssl 生成的签名看起来与 pyjwt 生成的签名不同