Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Scipt Working Fine in PC but Not on Android Devices

Discussion in 'Android' started by aepio92, May 13, 2021.

  1. aepio92

    aepio92

    Joined:
    Sep 9, 2017
    Posts:
    7
    I've a wall run mechanics in my game while you leave the movement joystick it the player will fall. This feature is working fine in PC but not in mobile devices. Here is my Code-
    also uploading two videos one is in editor & another one is recorded on android device-
    also tried different devices all them are having same problem.

    android gameplay-

    pc gameplay-


    WallRun.cs
    Code (CSharp):
    1.  
    2. public class ImplosionSuitWallRun : MonoBehaviour
    3. {
    4.     [Header("References")]
    5.     public int WallRunLayerIndexIndex;
    6.     public GameObject ImplosionGun;
    7.     public Rig GunIk;
    8.     public Joystick MovementJoystick;
    9.     public float MovementDampning;
    10.     public ImplosionSuitCameraController CameraController;
    11.     public GameObject WallRunCheck;
    12.     public float WallRunHitRange;
    13.     public Camera MainCamera;
    14.  
    15.     [HideInInspector]
    16.     public bool IsWallRunning;
    17.     [HideInInspector]
    18.     public bool IsInWallRunMode;
    19.  
    20.     ImplosionSuitAimDownSight ADSLogic;
    21.     ImplosionSuitFire FireLogic;
    22.     ImplosionSuitMovement MovementLogic;
    23.     ImplisionSuitFall FallLogic;
    24.     Animator animator;
    25.     Rigidbody RB;
    26.  
    27.  
    28.     void Start()
    29.     {
    30.         ADSLogic = GetComponent<ImplosionSuitAimDownSight>();
    31.         FireLogic = GetComponent<ImplosionSuitFire>();
    32.         animator = GetComponent<Animator>();
    33.         RB = GetComponent<Rigidbody>();
    34.         FallLogic = GetComponent<ImplisionSuitFall>();
    35.         MovementLogic = GetComponent<ImplosionSuitMovement>();
    36.     }
    37.    
    38.     private void FixedUpdate()
    39.     {
    40.         CheckWall();
    41.         CheckWallRunStatus();
    42.     }
    43.  
    44.     public void ActivateWallRun()
    45.     {
    46.         IsInWallRunMode = true;
    47.         ADSLogic.AimingDownSight = false;
    48.         FireLogic.IsInFiringMode = false;
    49.         ImplosionGun.SetActive(false);
    50.         GunIk.weight = 0;
    51.     }
    52.  
    53.     void CheckWall()
    54.     {
    55.         if (FallLogic.Falling == false)
    56.         {
    57.             RaycastHit WallRunHit;
    58.             Physics.Raycast(WallRunCheck.transform.position, MainCamera.transform.forward, out WallRunHit, WallRunHitRange);
    59.  
    60.             if (WallRunHit.collider != null)
    61.             {
    62.                 if (MovementLogic.input.magnitude == 0)
    63.                 {
    64.                     IsWallRunning = false;
    65.                     animator.SetTrigger("FallBack");
    66.                     RB.useGravity = false;
    67.                     RB.AddForce(transform.forward * -100, ForceMode.Impulse);
    68.                     IsInWallRunMode = true;
    69.                 }
    70.                 else
    71.                 {
    72.                     IsWallRunning = true;
    73.                     ADSLogic.AimingDownSight = false;
    74.                     FireLogic.IsInFiringMode = false;
    75.                     ImplosionGun.SetActive(false);
    76.                     GunIk.weight = 0;
    77.                     transform.rotation = Quaternion.LookRotation(-WallRunHit.normal);
    78.                 }
    79.             }
    80.             else
    81.             {
    82.                 if (IsWallRunning == true)
    83.                 {
    84.                     animator.SetTrigger("ClimbTop");
    85.                 }
    86.             }
    87.         }
    88.     }
    89.  
    90.     void CheckWallRunStatus()
    91.     {
    92.         if(IsWallRunning==true)
    93.         {
    94.             animator.SetLayerWeight(WallRunLayerIndexIndex, Mathf.Lerp(animator.GetLayerWeight(WallRunLayerIndexIndex), 1.0f, 10 * Time.deltaTime));
    95.         }
    96.         else
    97.         {
    98.             animator.SetLayerWeight(WallRunLayerIndexIndex, Mathf.Lerp(animator.GetLayerWeight(WallRunLayerIndexIndex), 0.0f, 10 * Time.deltaTime));
    99.         }
    100.     }
    101.  
    102.     void ApplyUpForce()
    103.     {
    104.         RB.AddForce(transform.up * 5);
    105.     }
    106.  
    107.     void ApplyForwardForce()
    108.     {
    109.         RB.AddForce(transform.forward * 5);
    110.     }
    111.  
    112.     void WallRunEnd()
    113.     {
    114.         IsWallRunning = false;
    115.         ADSLogic.AimingDownSight = false;
    116.         FireLogic.IsInFiringMode = false;
    117.         RB.useGravity = true;
    118.         ImplosionGun.SetActive(true);
    119.         IsInWallRunMode = false;
    120.         Invoke("SetGunIK", 0.05f);
    121.     }
    122.  
    123.     void SetGunIK()
    124.     {
    125.         GunIk.weight = 1;
    126.     }
    127.  
    Fall.cs
    Code (CSharp):
    1.  
    2. public class ImplisionSuitFall : MonoBehaviour
    3. {
    4.     [Header("references")]
    5.     public float FallForce;
    6.     public int FallLayerIndex;
    7.     public GameObject HeightTracker;
    8.     public Rig GunIK;
    9.  
    10.     [HideInInspector]
    11.     public bool Falling;
    12.  
    13.     ImplosionSuitFire FireLogic;
    14.     ImplosionSuitAimDownSight ADSLogic;
    15.     ImplosionSuitWallRun WallRunLogic;
    16.     Animator animator;
    17.     Rigidbody RB;
    18.     float StartHeight;
    19.     public Shaker MyShaker;
    20.     public ShakePreset MyShakePreset;
    21.  
    22.     void Start()
    23.     {
    24.         animator = GetComponent<Animator>();
    25.         RB = GetComponent<Rigidbody>();
    26.         WallRunLogic = GetComponent<ImplosionSuitWallRun>();
    27.         FireLogic = GetComponent<ImplosionSuitFire>();
    28.         ADSLogic = GetComponent<ImplosionSuitAimDownSight>();
    29.     }
    30.  
    31.     void Update()
    32.     {
    33.         CheckHeight();
    34.     }
    35.  
    36.     void CheckHeight()
    37.     {
    38.         RaycastHit TrackerHit;
    39.         Physics.Raycast(HeightTracker.transform.position, transform.up * -1, out TrackerHit);
    40.  
    41.         if(WallRunLogic.IsWallRunning==false)
    42.         {
    43.             if(WallRunLogic.IsInWallRunMode==false)
    44.             {
    45.                 float Height = (TrackerHit.point - HeightTracker.transform.position).magnitude;
    46.                 if(Height>3)
    47.                 {
    48.                     if(StartHeight<Height)
    49.                     {
    50.                         StartHeight = Height;
    51.                     }
    52.                 }
    53.                 if(RB.velocity.y<-0.1)
    54.                 {
    55.                     if (StartHeight > 3)
    56.                     {
    57.                         Debug.Log("Falling");
    58.                         Falling = true;
    59.                         animator.SetLayerWeight(FallLayerIndex, Mathf.Lerp(animator.GetLayerWeight(FallLayerIndex), 1.0f, 10 * Time.deltaTime));
    60.                         //animator.SetLayerWeight(FallLayerIndex, 1);
    61.                         FallForce = 5;
    62.                         SetGunIK(0);
    63.                         RB.AddForce(transform.up * -FallForce, ForceMode.VelocityChange);
    64.                     }
    65.                 }
    66.                 else
    67.                 {
    68.                     if (StartHeight > 3)
    69.                     {
    70.                         animator.SetTrigger("Land");
    71.                         MyShaker.Shake(MyShakePreset);
    72.                     }
    73.                     Falling = false;
    74.                     StartHeight = 0;
    75.                     Debug.Log("NotFalling");
    76.                     animator.SetLayerWeight(FallLayerIndex, Mathf.Lerp(animator.GetLayerWeight(FallLayerIndex), 0.0f, 20 * Time.deltaTime));
    77.                     //animator.SetLayerWeight(FallLayerIndex, 0);
    78.                     SetGunIK(1);
    79.                 }
    80.             }
    81.         }
    82.     }
    83.  
    84.     public void SetGunIK(float Weight)
    85.     {
    86.         GunIK.weight = Weight;
    87.     }
    88. }
    89.  
     
  2. vagelis199

    vagelis199

    Joined:
    Jul 27, 2012
    Posts:
    83
    Honestly, I don't understand the problem, on both videos when you release the joystick the character falls
     
unityunity