Jump to content
Unity Insider Forum

AstroHelsi

Members
  • Posts

    8
  • Joined

  • Last visited

AstroHelsi's Achievements

Newbie

Newbie (1/3)

0

Reputation

  1. Habe es jetzt noch Mal probiert. movedirection (bei deinem Script velocity) ist nicht mehr lokal. Die alte Position wird im Vektor3 "altepos" gespeichert. Das Sprungverhalten hat sich geändert und ich bleibe weiterhin an der Decke hängen. Ich scheine bei diesem Script nicht nur an der Decke zu hängen 😕 using System.Collections; using System.Collections.Generic; using UnityEngine; public class NewBehaviourScript : MonoBehaviour { private Vector3 altepos; private Vector3 movedirection; private float zdir; private float ydir; void Start() { } // Update is called once per frame void Update() { // Bewegungsvektor zdir = Input.GetAxis("Horizontal"); ydir -= gravity * Time.deltaTime; movedirection = new Vector3(0, ydir, zdir * movespeed); altepos = transform.position; controller.Move(movedirection * Time.deltaTime); movedirection = (transform.position - altepos) / Time.deltaTime; } }
  2. Stimmt. Ich habe das Problem mit der Variable gelöst, jedoch ohne Erfolg. Ich lasse es mit dem springen einfach, kommt ja zum Glück nicht häufig vor, das man in irgendwelche Ecken springt. Trotzdem danke
  3. Ich weis es leider auch nicht. Ich habe die gespeichert und danach von der aktuellen die alte abgezogen 😕 Ich mache hier irgendwo einen groben Fehler. Habe jetzt die Jump und Move actionen für den Post rausgenommen aus dem Script. using System.Collections; using System.Collections.Generic; using UnityEngine; public class CharController : MonoBehaviour { // Variablen private CharacterController controller; [SerializeField] private float movespeed = 0f; [SerializeField] private float walkspeed = 3f; [SerializeField] private float runspeed = 4f; [SerializeField] private float jumpheight = 4f; [SerializeField] private float ydir; [SerializeField] private float gravity = 9.81f; [SerializeField] private float xdir; private float velocity; private Vector3 altepos; void Start() { controller = GetComponent<CharacterController>(); } // Update is called once per frame void Update() { float zdir = Input.GetAxis("Horizontal"); Vector3 movedirection = new Vector3(0, ydir, zdir); ydir -= gravity * Time.deltaTime; altepos = transform.position; movedirection *= movespeed; controller.Move(movedirection * Time.deltaTime); movedirection = (transform.position - altepos) / Time.deltaTime; } }
  4. Du hast recht ,da funktioniert es nicht. Ich bekomme deine Vorgehensweise leider nicht hin.
  5. Danke für deine Hilfe. Ich hab es jetzt gelöst. Bin anders vorgegangen. Es gibt mit Sicherheit schönere, elegantere und logischere Art und Weisen das zu lösen aber so funktioniert es auch ganz gut Ich habe die Kollision mittels CollisionFlags.Above abgefragt. In der If Abfrage habe ich den Wert 0.8 festgelegt. Ich bin nicht logisch auf die 0.8 gekommen, sondern habe paar Werte probiert. Was sagst du dazu ? using System.Collections; using System.Collections.Generic; using UnityEngine; public class CharController : MonoBehaviour { // Variablen private CharacterController controller; [SerializeField] private float movespeed = 0f; [SerializeField] private float walkspeed = 3f; [SerializeField] private float runspeed = 4f; [SerializeField] private float jumpheight = 4f; [SerializeField] private float ydir; [SerializeField] private float gravity = 9.81f; void Start() { controller = GetComponent<CharacterController>(); } // Update is called once per frame void Update() { float zdir = Input.GetAxis("Horizontal"); Vector3 movedirection = new Vector3(0, 0, zdir); if (movedirection != Vector3.zero && !Input.GetKey(KeyCode.LeftShift)) { // WALK movespeed = walkspeed; } else if (movedirection != Vector3.zero && Input.GetKey(KeyCode.LeftShift)) { // RUN movespeed = runspeed; } else if (movedirection == Vector3.zero) { // IDLE } if (controller.isGrounded && Input.GetKey(KeyCode.Space)) { ydir = jumpheight; } else if (controller.isGrounded==true) { ydir = 0; } else if (controller.collisionFlags == CollisionFlags.Above) { ydir = -0.8f; } ydir -= gravity * Time.deltaTime; movedirection.y = ydir; movedirection *= movespeed; Vector3 finalmovement = movedirection; controller.Move(finalmovement * Time.deltaTime); } }
  6. Nein der Ground-Check hat problemlos funktioniert. Ich habe das jetzt auch tatsächlich mit isGrounded gelöst, ist wirklich einfacher. Jetzt klappt der Sprung auch super. Wenn ich jedoch von unten an ein Objekt ranspringe, dann bleibt er daran kurz hängen und fällt dann runter. Mich interessiert es, wie man an ein solches Problem in Unity herangeht? Ich habe an einen Raycast gedacht, der prüft, ob eine Kolission über dem Spieler stattfindet. Gibt es da auch eine einfachere Variante? Oder wie gehen die Pros mit so einem Verhalten um ? Die Gravitation hab ich in der neuen Steuerung in einem Vektor gelöst und diese dann auf den movedirection Vektor addiert. Mir ist die Vorgehensweise noch nicht klar. using System.Collections; using System.Collections.Generic; using UnityEngine; public class CharController : MonoBehaviour { // Variablen private CharacterController controller; [SerializeField] private float movespeed = 0f; [SerializeField] private float walkspeed = 3f; [SerializeField] private float runspeed = 4f; [SerializeField] private float jumpheight = 12f; public float gravity; private float currentGravity = 0f; void Start() { controller = GetComponent<CharacterController>(); } // Update is called once per frame void Update() { float zdir = Input.GetAxis("Horizontal"); Vector3 movedirection = new Vector3(0, 0, zdir); if (movedirection != Vector3.zero && !Input.GetKey(KeyCode.LeftShift)) { // WALK movespeed = walkspeed; } else if (movedirection != Vector3.zero && Input.GetKey(KeyCode.LeftShift)) { // RUN movespeed = runspeed; } else if (movedirection == Vector3.zero) { // IDLE } if (controller.isGrounded && Input.GetKeyDown(KeyCode.Space)) { // JUMP currentGravity *= -jumpheight; } movedirection *= movespeed; Vector3 finalmovement = movedirection + ApplyGravity(); controller.Move(finalmovement * Time.deltaTime); } Vector3 ApplyGravity() { Vector3 gravityMovement = new Vector3(0, -currentGravity, 0); currentGravity += gravity * Time.deltaTime; if (controller.isGrounded) { if (currentGravity > 1f) currentGravity = 1f; } return gravityMovement; } }
  7. Es sind beide gelöscht. Ich kann das Verhalten nur wiederholen, in dem ich die Kapsel in der Hierachy dupliziere. Ansonsten sind alle Parameter in Bezug zum Würfel gleich. Ich habe es mehrfach überprüft es ist wirklich alles genau so. Ich verstehe nicht woran es liegen kann.
  8. Hallo leute ich bin neu hier im Forum Ich habe ein Problem, welches mich hier zum verzweifeln bringt. Ich habe ein Script erstellt, dass eine Kapsel mittels Character Controller bewegen lässt. Jetzt habe ich Gravitation hinzugefügt und alles klappt soweit ganz gut. Das Script funktioniert jedoch NUR auf dieser Kapsel Wenn ich das gleiche Script auf ein anderes Objekt, wie z.B. einen Würfel packe, funktioniert es nicht mehr. Ich habe dem Würfel natürlich den Character Controller hinzugefügt und jegliche Parameter der Kapsel übernommen. Die Kapsel fällt normal (langsam) runter. Der Würfel jedoch schießt nach unten. Wenn er auf dem Ground steht, läd sich die Gravitation auf. Er wird somit schneller beim Fall. Weis jemand woran es liegt? using System.Collections; using System.Collections.Generic; using UnityEngine; public class TEST : MonoBehaviour { // Variablen private CharacterController controller; [SerializeField] private float movespeed = 0f; [SerializeField] private float walkspeed = 3f; [SerializeField] private float runspeed = 4f; [SerializeField] private bool isgrounded; [SerializeField] private float groundcheckdistance; [SerializeField] private LayerMask groundmask; [SerializeField] private float gravity; private Vector3 velocity; void Start() { controller = GetComponent<CharacterController>(); } // Update is called once per frame void Update() { move(); } void move() { isgrounded = Physics.CheckSphere(transform.position, groundcheckdistance, groundmask); if (isgrounded && velocity.y < 0) { velocity.y = 2f; } float zdir = Input.GetAxis("Horizontal"); Vector3 movedirection = new Vector3(0, 0, zdir); if (movedirection != Vector3.zero && !Input.GetKey(KeyCode.LeftShift)) { // WALK movespeed = walkspeed; } else if (movedirection != Vector3.zero && Input.GetKey(KeyCode.LeftShift)) { // RUN movespeed = runspeed; } else if (movedirection == Vector3.zero) { // IDLE } controller.Move(movedirection * movespeed * Time.deltaTime); velocity.y += gravity * Time.deltaTime; controller.Move(velocity * Time.deltaTime); } }
×
×
  • Create New...