图片:https://i.stack.imgur.com/O9T5t.png
嗨,我最近刚试过“团结中的一个球”的教程。在本教程中,您只教了摄像机如何从1个定点跟踪球。但我想编辑,这样相机将始终后面的球跟随,他们的关键,WASD总是一样的。它类似于openworld游戏,如GTA V、RDR2等。
我尝试使用Cinemachine的vcam和免费摄像头,它的工作为相机跟随,但关键的WASD混乱,例如W应该是前进,但现在它正在向后移动。
这是我移动播放器的PlayerController代码,我相信是在OnMove函数上。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
// Include the namespace required to use Unity UI and Input System
using UnityEngine.InputSystem;
using TMPro;
public class PlayerController : MonoBehaviour
{
// Create public variables for player speed, and for the Text UI game objects
public float speed;
public TextMeshProUGUI countText;
public GameObject winTextObject;
private float movementX;
private float movementY;
private Rigidbody rb;
private int count;
// At the start of the game..
void Start()
{
// Assign the Rigidbody component to our private rb variable
rb = GetComponent<Rigidbody>();
// Set the count to zero
count = 0;
SetCountText();
// Set the text property of the Win Text UI to an empty string, making the 'You Win' (game over message) blank
winTextObject.SetActive(false);
}
void FixedUpdate()
{
// Create a Vector3 variable, and assign X and Z to feature the horizontal and vertical float variables above
Vector3 movement = new Vector3(movementX, 0.0f, movementY);
rb.AddForce(movement * speed);
}
void OnTriggerEnter(Collider other)
{
// ..and if the GameObject you intersect has the tag 'Pick Up' assigned to it..
if (other.gameObject.CompareTag("PickUp"))
{
other.gameObject.SetActive(false);
// Add one to the score variable 'count'
count = count + 1;
// Run the 'SetCountText()' function (see below)
SetCountText();
}
}
void OnMove(InputValue value)
{
Vector2 v = value.Get<Vector2>();
movementX = v.x;
movementY = v.y;
}
void SetCountText()
{
countText.text = "Count: " + count.ToString();
if (count >= 12)
{
// Set the text value of your 'winText'
winTextObject.SetActive(true);
Time.timeScale = 0;
}
}
}发布于 2022-05-04 09:36:50
为了解决这个问题,你必须根据相机调整输入轴。
Transform.TransformDirection("// input vector..");如果改正率低,这个问题就可以解决。
void FixedUpdate()
{
Vector3 movement = new Vector3(movementX, 0.0f, movementY);
// affect base on camera direction
movement = Camera.main.transform.TransformDirection(movement);
movement.y = 0;
rb.AddForce(movement.normalized * speed);
}https://stackoverflow.com/questions/72110678
复制相似问题