Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

slide script not working...

Discussion in 'Scripting' started by Twitterfingers, Sep 18, 2018.

  1. Twitterfingers

    Twitterfingers

    Joined:
    Jul 29, 2018
    Posts:
    12
    This is my double jump script but it's giving me errors.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections.Generic;
    4. using System.Collections;
    5.  
    6. public class Slide : MonoBehaviour
    7. {
    8.     private Vector3 moveDirection;
    9.  
    10.     public const float maxSlideTime = 10f;
    11.     public float slideDistance = 10f;
    12.     public float slideStoppingSpeed = 1.0f;
    13.     public float currentSlideTIme;
    14.     public float slideSpeed = 1;
    15.     public CharacterController characterController;
    16.  
    17.     void Start()
    18.     {
    19.        characterController = gameObject.GetComponent<CharacterController>();
    20.     }
    21.  
    22.     void Update()
    23.     {
    24.         if (Input.GetKeyDown("x"))
    25.         {
    26.             currentSlideTIme = 0;
    27.          
    28.         }
    29.         if (currentSlideTIme < maxSlideTime)
    30.         {
    31.             moveDirection = transform.forward * slideDistance;
    32.             currentSlideTIme += slideStoppingSpeed;
    33.         }
    34.         else
    35.         {
    36.             moveDirection = Vector3.zero;
    37.         }
    38.         if (Input.GetKeyDown("x"))
    39.         {
    40.             characterController.height = 1f;
    41.         }
    42.         else
    43.         {
    44.             characterController.height = 1.8f;
    45.         }
    46.         characterController.Move(moveDirection * Time.deltaTime * slideSpeed);
    47.     }
    48. }
    49.  
    my character shakes for no reason and he won't crouch... I'm not sure what i'm doing wrong. Sorry about the title I was trying to check why it wasn't working and I thought it was the character limit.
     
  2. shawnrevels

    shawnrevels

    Joined:
    Aug 13, 2014
    Posts:
    86
    Why are you calling the same input for x twice?
     
  3. shawnrevels

    shawnrevels

    Joined:
    Aug 13, 2014
    Posts:
    86
    When you hit x you are executing different things. And I don't see where your jump is.. is jump x or is slide x?
     
  4. Twitterfingers

    Twitterfingers

    Joined:
    Jul 29, 2018
    Posts:
    12
    Ill try the first suggestion and my double jump is attached to my character controller.
     
  5. shawnrevels

    shawnrevels

    Joined:
    Aug 13, 2014
    Posts:
    86
    Yeah. You shouldnt use x input for jump and slide. You should use space for jump. In my opinion
     
  6. Twitterfingers

    Twitterfingers

    Joined:
    Jul 29, 2018
    Posts:
    12
    Double jump and Jump use spacebar and only slide uses X but slide always F*** with my double jump. I've got another script that crouches but it doesn't effect any other scripts that's why I am so confused.
     
  7. shawnrevels

    shawnrevels

    Joined:
    Aug 13, 2014
    Posts:
    86
    Code (CSharp):
    1. void Update()
    2.     {
    3.         if (Input.GetKeyDown("x"))
    4.         {
    5.             currentSlideTIme = 0;
    6.             characterController.height = 1f;
    7.         }else
    8.         {
    9.             characterController.height = 1.8f;
    10.         }
    11.  
    12.         if (currentSlideTIme < maxSlideTime)
    13.         {
    14.             moveDirection = transform.forward * slideDistance;
    15.             currentSlideTIme += slideStoppingSpeed;
    16.         }
    17.         else
    18.         {
    19.             moveDirection = Vector3.zero;
    20.         }
    21.      
    22.         characterController.Move(moveDirection * Time.deltaTime * slideSpeed);
    23.     }