using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Player : MonoBehaviour
{
public float speed;
public float rotationSpeed;
public float dashspeed;
private float Cooldown;
public int currentStamina;
//fügt die Stamina Klasse ein
public Stamina staminaa;
void Start()
{
currentStamina = 100;
staminaa.SetMaxStamina(100);
}
void Update()
{
float x = Input.GetAxisRaw("Horizontal");
float y = Input.GetAxisRaw("Vertical");
Vector3 movementDirection = new Vector3(x, 0, y);
movementDirection.Normalize();
if (Input.GetKeyDown("f") && currentStamina >= 25)
{
transform.position += transform.TransformDirection(Vector3.forward) * dashspeed;
TakeDamage(25);
}
else
{
transform.Translate(movementDirection * speed * Time.deltaTime, Space.World);
}
if (movementDirection != Vector3.zero)
{
Quaternion toRotation = Quaternion.LookRotation(movementDirection, Vector3.up);
transform.rotation = Quaternion.RotateTowards(transform.rotation, toRotation, rotationSpeed * Time.deltaTime);
}
//Staminacharge and Cooldown
if (Cooldown >= 2 && currentStamina != 100)
{
ChargeAgain(5);
Cooldown = 0;
}
else if (currentStamina != 100)
{
//Cooldown
Cooldown += Time.deltaTime;
}
}
void TakeDamage(int damage)
{
currentStamina -= damage;
staminaa.SetStamina(currentStamina);
}
void ChargeAgain(int charge)
{
currentStamina += charge;
staminaa.SetStamina(currentStamina);
}
}
Changing transform equals teleporting.You should be using rigidbody for movement if you want collisions.Also this seems like the wrong subforum as the Input system seems irrelevant to the issue at hand(collisions)
could you show me how it would look like?
One option would be to use: Unity - Scripting API: Rigidbody.MovePosition