Search Unity

Blink Ability Problem

Discussion in 'Scripting' started by peepercreeper, Jan 18, 2019.

  1. peepercreeper

    peepercreeper

    Joined:
    Jan 14, 2019
    Posts:
    2
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Blink : MonoBehaviour {
    6.     public float BlinkDist = 2.5f;
    7.     private bool ASD;
    8.     private int Charge = 3;
    9.     public float Recharge = 3;
    10.     public int RechargeLim = 4;
    11.     void Start(){
    12.         Recharge = RechargeLim;
    13.     }
    14.     void Update () {
    15.         ASD = false;
    16.         if(Charge <= 2){
    17.             Recharge = Recharge - Time.deltaTime;
    18.             if(Recharge <= 0){
    19.                 Charge++;
    20.                 Recharge = RechargeLim;
    21.             }
    22.         }
    23.         if(Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D)){
    24.             ASD = true;
    25.         }
    26.         if(Charge >= 1){
    27.             if(Input.GetKeyDown(KeyCode.E) && Input.GetKey(KeyCode.D)){
    28.                 transform.Translate(Vector3.right * BlinkDist);
    29.                 Charge--;
    30.             }
    31.             if(Input.GetKeyDown(KeyCode.E) && Input.GetKey(KeyCode.S)){
    32.                 transform.Translate(-Vector3.forward * BlinkDist);
    33.                 Charge--;
    34.             }
    35.             if(Input.GetKeyDown(KeyCode.E) && Input.GetKey(KeyCode.A)){
    36.                 transform.Translate(-Vector3.right * BlinkDist);
    37.                 Charge--;
    38.             }
    39.             if(Input.GetKeyDown(KeyCode.E)){
    40.                 if(ASD == false){
    41.                     transform.Translate(Vector3.forward * BlinkDist);
    42.                     Charge--;
    43.                 }
    44.             }
    45.         }
    46.     }
    47. }
    So i have this blink script that works just fine but the only problem is it doesnt go up ramps it stops the teleport when it hits a ramp that you can normally walk up without teleporting, and i need to find a way to be able to change the max ramp angle you can blink upwards on in the editor, can some provide help with this problem?

    here is the script:
     
  2. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    If you don't want to take into account the added distance from the added angle(to go 1 meter to the right while also going at 45 degrees up you need to go something like 1.44 meters) what you can do is find the position you "landed" on, do a raycast from the sky to find the ground level and teleport the player there.