Cinemachine folgen der Kamera -Stottern, wenn das Zielobjekt, das die starre Schwerkraft befolgt, deaktiviert ist. Wie kC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Cinemachine folgen der Kamera -Stottern, wenn das Zielobjekt, das die starre Schwerkraft befolgt, deaktiviert ist. Wie k

Post by Anonymous »

Wenn die Schwerkraft verwendet wird, funktioniert es gut, dass die Kamera glatt folgt. Und ich habe im starre Körper versucht, die Interpolat -Eigenschaft auf Interpolieren zu setzen, aber es hat sich nicht viel geändert. src = "https://i.static.net/qo6omjnz.jpg"/>
und dies ist die Cinemachine -Kameraeinstellungen nach dem Spiel, da ich die Player -Ball -Prefab ein bisschen später erstelle, um ein Skript zu finden, um es zu finden. src = "https://i.static.net/revlu4kz.jpg"/>
Das Drehbuch, das den an den Ball befestigten Ball
bewegt

Code: Select all

using UnityEngine;
using UnityEngine.InputSystem;

[RequireComponent(typeof(Rigidbody))]
public class MovePlayer : MonoBehaviour
{
[Header("Movement Settings")]
public float forwardForce = 10f;
public float sideForce = 8f;
public float laneLimit = 4f;

private Rigidbody rb;

void Start()
{
rb = GetComponent();
rb.freezeRotation = false;
rb.interpolation = RigidbodyInterpolation.Interpolate;
}

void FixedUpdate()
{
// Apply forward force
rb.AddForce(Vector3.forward * forwardForce, ForceMode.Force);

// Side input
float horizontalInput = 0f;
if (Keyboard.current.aKey.isPressed || Keyboard.current.leftArrowKey.isPressed)
horizontalInput = -1f;
else if (Keyboard.current.dKey.isPressed || Keyboard.current.rightArrowKey.isPressed)
horizontalInput = 1f;

rb.AddForce(Vector3.right * horizontalInput * sideForce, ForceMode.Force);

// Clamp velocity instead of position
Vector3 velocity = rb.linearVelocity;
velocity.x = Mathf.Clamp(velocity.x, -sideForce, sideForce);
rb.linearVelocity = velocity;
}
}
< /code>
Dies ist der Teil des Skripts im Start () -Teil, der den Ball erstellt und der Cinemachine -Kamera zuweisen. Dieses Skript ist an leere GameObject angeschlossen. < /p>
void Start()
{
// Spawn player
ball = Instantiate(ballPrefab);
// Position the ball a little further up so it doesn't fall through the floor immediately
ball.transform.position = new Vector3(0, wallHeight + 0.5f, 0);
ball.tag = "Player";
ballRb = ball.GetComponent();

// Attach Cinemachine camera to follow the ball
var cineCam = FindFirstObjectByType();
if (cineCam != null)
{
cineCam.Follow = ball.transform;
cineCam.LookAt = ball.transform;

}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post