C# 是否停止基于帧速率更改角色跳跃高度?
我已经为我的角色控制器编写了一个函数,允许玩家角色执行跳转动作。我目前使用两台显示器,一台是60hz显示器,另一台是120hz显示器。在120hz显示器上运行游戏时,跳跃功能的作用与我预期的一样,但在60hz显示器上运行时,角色的跳跃比我预期的要高。我知道这与使用Time.deltatime有关,但我不知道如何在跳转函数中正确实现它。代码如下:C# 是否停止基于帧速率更改角色跳跃高度?,c#,unity3d,C#,Unity3d,我已经为我的角色控制器编写了一个函数,允许玩家角色执行跳转动作。我目前使用两台显示器,一台是60hz显示器,另一台是120hz显示器。在120hz显示器上运行游戏时,跳跃功能的作用与我预期的一样,但在60hz显示器上运行时,角色的跳跃比我预期的要高。我知道这与使用Time.deltatime有关,但我不知道如何在跳转函数中正确实现它。代码如下: void PlayerJump() { if (controller.isGrounded) { if(In
void PlayerJump()
{
if (controller.isGrounded)
{
if(Input.GetButtonDown("Jump"))
{
moveDirection.y = jumpForce;
}
else
{
moveDirection.y = fallSpeed;
}
}
moveDirection.y = moveDirection.y + (Physics.gravity.y ) ;
}
以下是上述函数的所有内容,以进一步澄清:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class platforming_controller_2D : MonoBehaviour
{
public float movementSpeed;
public float jumpForce;
public float gravityScale;
public float fallSpeed;
public double jumpGravity = (-9.81 * 0.045);
public Animator anim;
public CharacterController controller;
private Vector3 moveDirection;
void Start()
{
controller = GetComponent<CharacterController>();
anim = GetComponent<Animator>();
}
void Update()
{
PlayerMovement();
playRunAnimation();
PlayerJump();
playJumpAnimation();
controller.Move(moveDirection * Time.deltaTime);
}
void PlayerMovement()
{
//float moveVertical = Input.GetAxis("Vertical");
float moveHorizontal = Input.GetAxis("Horizontal");
Vector3 newPosition = new Vector3(moveHorizontal, 0.0f, 0.0f);
moveDirection = new Vector3(Input.GetAxis("Horizontal") * movementSpeed, moveDirection.y, 0.0f);
transform.LookAt(newPosition + transform.position);
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
公共类平台\u控制器\u 2D:单行为
{
公众浮标移动速度;
公共安全部队;
公众浮标;
公共交通速度;
公共双跳重力=(-9.81*0.045);
公共动画;
公共字符控制器;
专用矢量3移动方向;
void Start()
{
控制器=GetComponent();
anim=GetComponent();
}
无效更新()
{
PlayerMovement();
playRunAnimation();
PlayerJump();
播放动画();
控制器移动(移动方向*时间增量);
}
无效玩家移动()
{
//float moveVertical=Input.GetAxis(“垂直”);
float moveHorizontal=Input.GetAxis(“水平”);
矢量3新位置=新矢量3(水平移动,0.0f,0.0f);
moveDirection=新矢量3(Input.GetAxis(“水平”)*movementSpeed,moveDirection.y,0.0f);
transform.LookAt(newPosition+transform.position);
}
需要更多信息——moveDirection.y是如何使用的?如果它使用Unity的物理,请将所有刚体运动/跳跃放在FixedUpdate()中。