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. Dismiss Notice

Question Non-physic dash on slopes

Discussion in 'Scripting' started by Sp1ceForce, Aug 14, 2023.

  1. Sp1ceForce

    Sp1ceForce

    Joined:
    Aug 13, 2020
    Posts:
    5
    Hello, right now i am working on a skill system for my game, and i have some problems with dash.
    When I do a dash on a flat surface - everything is ok, but when I try to dash on an incline, the character makes a short dash, can somebody help, please
    Here's the code for dash
    Code (CSharp):
    1.     public override void StartCast()
    2.     {
    3.         if(!canCast) return;
    4.  
    5.         Vector3 blinkDirection = casterObject.GetComponent<MoveController>().CameraRelatedInputVector;
    6.         if(blinkDirection == Vector3.zero) blinkDirection = casterObject.transform.forward;
    7.         RaycastHit hit;
    8.         Vector3 endPos;
    9.         if(!Physics.Raycast(casterObject.transform.position,blinkDirection,out hit, spellData.BlinkDistance)){
    10.             endPos = casterObject.transform.position + blinkDirection * spellData.BlinkDistance;
    11.         }
    12.         else{
    13.             endPos = casterObject.transform.position + ((hit.point - casterObject.transform.position) * spellData.OnWallHitOffset);
    14.         }
    15.         canCast = false;
    16.         casterObject.transform.DOMove(endPos,BlinkDuration).OnStart(() => OnBlinkStart()).OnComplete(() => OnBlinkEnd());
    17.     }
    18.  
    Also, for movement i use character controller.
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,769
    You'll probably want to dash parallel to the ground, which likely means involves raycasting down at the ground, and using the RaycastHit normal in
    Vector3.Cross
    to generate said direction.

    The other direction you use in the cross product will depend on your particular game.
     
    Sp1ceForce, Yoreki and Kurt-Dekker like this.
  3. Sp1ceForce

    Sp1ceForce

    Joined:
    Aug 13, 2020
    Posts:
    5
    Thanks, it worked
     
    spiney199 likes this.