Answer the question
In order to leave comments, you need to log in
Character bug when jumping unity?
There is a character who must walk forward, backward and jump. But with a few jumps, he starts to stiffly sausage, he starts to fly away in different directions and spin, how can this situation be corrected?
Thank you very much
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Managament : MonoBehaviour {
private GameObject player; //Переменна объекта персонажа с которым будем работать.
public int speed = 6; //постоянная скорость перемещения персонажа
public int jump = 3; //Высота прыжка
public Animation animation; // Анимация
void Start () {
player = (GameObject)this.gameObject; //Задаем что наш персонаж это объект на котором расположен скрипт
}
void Update () {
animation = GetComponent<Animation>();
if(Input.GetKey (KeyCode.A)) {
player.transform.position += player.transform.right * speed * Time.deltaTime; //перемещаем в лево
animation.Play("running");
}
if(Input.GetKey (KeyCode.D)){
player.transform.position -= player.transform.right * speed * Time.deltaTime; //перемещаем в право
animation.Play("running");
}
if(Input.GetKey (KeyCode.Space)) {
player.transform.position += player.transform.up * jump * Time.deltaTime; //Прыгаем
animation.Play("jump");
}
}
}
Answer the question
In order to leave comments, you need to log in
Probably you are not saying something, when you jump (by the way, this is not a jump at all), the object simply rises while you press the space bar. There is no more logic there.
But if you use physics there (which you kept silent about), then the objects must be moved by physics, and not change its coordinates.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question