Question by
smarjanovicng · Sep 14, 2018 at 09:55 AM ·
scripting problemjumpingcollison
My character wont jump when on downward slope or when on the edge of object that is on?
Hello guys, the problem is when i jump on an object and i need to jump again immediately, my character just ignores the button and dosent jump, here's the scripts so if anyone can help me, thank you!
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerController : MonoBehaviour {
//kretanje i skaknje
public float brzinaKretanja;
public float skok;
public CharacterController controller;
public Vector3 smjerKretanja;
public float gravityScale;
//Zvukovi kretanja
public AudioSource jumpingSound;
public AudioSource movingSound;
public float velocity;
//Knockback varijable
public float knockBackForce;
public float knockBackTime;
private float knockBackCounter;
//Dash varijable
public float dashForce;
public float dashTime;
private float dashCounter;
public Animator anim;
public Color newColor;
public bool facingRight;
void Start () {
Cursor.visible = false;
controller = GetComponent<CharacterController>();
}
void Update() {
if (knockBackCounter <= 0) {
float yStore = smjerKretanja.y;
float zStore = smjerKretanja.z;
smjerKretanja = (transform.forward * (Input.GetAxis("Vertical"))+(transform.right*Input.GetAxis("Horizontal")));
smjerKretanja = smjerKretanja * brzinaKretanja;
smjerKretanja.y = yStore;
if (controller.isGrounded)
{
smjerKretanja.y = 0f;
if (Input.GetButtonDown("Jump") && controller.isGrounded)
{
smjerKretanja.y = skok;
}
}
//Onemogućavanje kretanje po Z osi
smjerKretanja.z = zStore;
//Dash funkcija
if (Input.GetButtonDown("Dash") && controller.isGrounded)
{
Vector3 dash;
dashCounter = dashTime;
dash = new Vector3(5f, 0, 0);
smjerKretanja = dash * dashForce;
}
}
else
{
knockBackCounter -= Time.deltaTime;
dashCounter -= Time.deltaTime;
}
//If za zvuk skoka
if (Input.GetButtonDown("Jump") && controller.isGrounded){
jumpingSound.Play();
}
smjerKretanja.y = smjerKretanja.y + (Physics.gravity.y * gravityScale*Time.deltaTime);
controller.Move(smjerKretanja *Time.deltaTime);
//Animator i animacije
anim.SetBool("isGrounded", controller.isGrounded);
anim.SetFloat("isMoving", (Mathf.Abs(Input.GetAxis("Vertical"))+Mathf.Abs(Input.GetAxis("Horizontal"))));
}
public void Knocback(Vector3 direction)
{
knockBackCounter = knockBackTime;
direction = new Vector3(-0.5f, 1f, 0);
smjerKretanja = direction * knockBackForce;
}
Comment
Answer by smarjanovicng · Sep 14, 2018 at 09:56 AM
smjerKretanja means movingDirection and skok means jump
Your answer
Follow this Question
Related Questions
Player not double jumping. 0 Answers
Unity 2D Enemy jump Question (Frog jump) 1 Answer
player not able to double jump 0 Answers
Enemy makes player glitch through walls 0 Answers
Character's jumping mechanism stuck into something invisible 1 Answer