Wie mache ich Player in Dash, ohne Charaktercontroller zu verwenden?C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Wie mache ich Player in Dash, ohne Charaktercontroller zu verwenden?

Post by Anonymous »

Ich möchte den Player -Dash machen und ich habe keinen Charaktercontroller verwendet, daher kann ich keine Lösung dafür finden. Ich habe ein Skript mit Hilfe von YouTube gemacht, aber ich denke, es gibt einen Fehler darin, bitte helfen Sie mir.

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
public float moveSpeed;

public Rigidbody rb;
public float jumpForce = 5f;
public bool isOnGround = true;

Vector3 direction;

// To make camera move in mouse direction
public Vector2 turn;

// The sensetivity of mouse
public float sensitivity = 5f;

public Vector3 velocity;

// For dashing
public bool dashing = true;
public float dashingPower = 20f;
public float dashingTime = 0.3f;
public float dashingCooldown = 0.75f;

[SerializeField] private TrailRenderer tr;

// Start is called before the first frame update
void Start()
{
moveSpeed = 11f;

rb = GetComponent();

// To hide the mouse on game sreen
Cursor.lockState = CursorLockMode.Locked;

tr.emitting = false;
}

// Update is called once per frame
void Update()
{
// To move the camera in the direction of mouse
turn.x += Input.GetAxis("Mouse X") * sensitivity;
transform.localRotation = Quaternion.Euler(0, turn.x, 0);

transform.Translate(moveSpeed*Input.GetAxis("Horizontal")*Time.deltaTime,0f,moveSpeed*Input.GetAxis("Vertical")*Time.deltaTime);

if (Input.GetKeyDown(KeyCode.Space) && isOnGround)
{
rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
isOnGround = false;
}

if (Input.GetKeyDown(KeyCode.Mouse0) && dashing)
{
StartCoroutine(Dash());
}

}

private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Ground"))
{
isOnGround = true;
}
}

private IEnumerator Dash()
{
dashing = true;
tr.emitting = true;

velocity = new Vector3(transform.forward.x * dashingPower,  0f, transform.forward.z * dashingPower);
yield return new WaitForSeconds(dashingTime);
velocity = Vector3.zero;
tr.emitting = false;
yield return new WaitForSeconds(dashingCooldown);
dashing = true;
}
}
Nachdem der Player beim Drücken der Maus nicht der Player streichelt, fügt sie nur den Trail hinzu, wenn die Armaturenbretttaste gedrückt wird, und auch die DashCooldown -Dose funktioniert nicht, wenn Sie nach dem anderen die DASH -Taste drücken.>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post