Unity grounded state is flickering for character. .isGrounded being used but still flickering





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















The grounded state for my character controller flickers on and off constantly at what seems to be every frame. From what I know, it's supposed to check if the player is grounded through player.isGrounded, but something else is moving it back up.



using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerCharacterController: MonoBehaviour {

static Animator anim;

public bool walking;

public GameObject playerModel, Hero;
//Transforms
public Transform playerCam, character, centerPoint;

private Vector3 moveDirection;

//character controller declaration
CharacterController player;

//Mouse Rotation
private float rotX, rotY;
//Mouse Y Position
public float mouseYPosition = 1f;
//Mouse Sensitivity
public float Sensitivity = 10f;
//Mouse Zoom
private float zoom;
public float zoomSpeed = 2;
//Clamping Zoom
public float zoomMin = -2f;
public float zoomMax = -10f;
public float rotationSpeed = 5f;
//Move Front Back left & Right
private float moveFB, moveLR;
//Movement Speed
public float Speed = 2f;
//Velocity of Gravity
public float verticalVelocity;
//Jump Distance
public float jumpDist = 5f;
//Multiple Jumps
int jumpTimes;
//To use with Dialogue Manager
public DialogueManager DiagM;

public AudioClip jumpSound;
public AudioClip HurtSound;
public AudioClip PunchSound;

AudioSource audioSource;

//knockback

public float knockBackForce;
public float knockBackTime;
private float knockBackCounter;


// Use this for initialization
void Start ()
{
//character controller
player = GameObject.Find("Player").GetComponent<CharacterController> ();

StartCoroutine(MyCoroutine(character));

anim = GetComponent<Animator>();

//mouse zoom
zoom = -3;
centerPoint.transform.position = playerCam.transform.position;
centerPoint.transform.parent = null;
audioSource = GetComponent<AudioSource>();
}

IEnumerator MyCoroutine (Transform character)
{
if (player.isGrounded == true)

{
anim.SetBool("isFalling",false);
//anim.SetBool("isIdling", true);
yield return new WaitForSeconds(0);
}

}
// Update is called once per frame

void Update ()
{
//Mouse Zoom Input
zoom += Input.GetAxis ("Mouse ScrollWheel") * zoomSpeed;

if (zoom > zoomMin)
zoom = zoomMin;
if (zoom < zoomMax)
zoom = zoomMax;

//Mouse Camera Input
playerCam.transform.localPosition = new Vector3 (0, 0, zoom);

//Mouse Rotation

rotX += Input.GetAxis ("Mouse X") * Sensitivity;
rotY -= Input.GetAxis ("Mouse Y") * Sensitivity;

//Clamp Camera
rotY = Mathf.Clamp (rotY, -60f, 60f);
playerCam.LookAt (centerPoint);
centerPoint.localRotation = Quaternion.Euler (rotY, rotX, 0);

//Movement Speed
if (knockBackCounter <= 0)
{
moveDirection = (transform.forward * Input.GetAxis("Vertical")) + (transform.right * Input.GetAxis("Horizontal"));
moveDirection = moveDirection * Speed;
moveDirection.y = verticalVelocity;

player.Move(moveDirection * Time.deltaTime);



//Movement Rotation

centerPoint.position = new Vector3 (character.position.x, character.position.y + mouseYPosition, character.position.z);

//knockback disable
//Movement Input

if (Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0)

{
transform.rotation = Quaternion.Euler(0f, centerPoint.rotation.eulerAngles.y, 0f);
Quaternion turnAngle = Quaternion.LookRotation(new Vector3(moveDirection.x, 0f, moveDirection.z));
playerModel.transform.rotation = Quaternion.Slerp(playerModel.transform.rotation, turnAngle, Time.deltaTime * rotationSpeed);

if (player.isGrounded == true)
{
anim.SetBool("isWalking", true);
anim.Play("Running");
}
}
else
{
StartCoroutine(MyCoroutine(character));
}

if (Input.GetButtonDown("LHand"))
{
audioSource.PlayOneShot(PunchSound, 1F);
anim.Play("RPunch");
}

if (player.isGrounded == true)
{
jumpTimes = 0;
//verticalVelocity = -Physics.gravity.y * Time.deltaTime;
verticalVelocity = 0;
}
else
{
verticalVelocity += Physics.gravity.y * Time.deltaTime;
anim.SetBool("isWalking", false);
anim.SetBool("isFalling", true);
}


if (jumpTimes < 1)
{
if (Input.GetButtonDown("Jump"))
{
verticalVelocity += jumpDist;
anim.Play("Jump");
audioSource.PlayOneShot(jumpSound, 1F);
jumpTimes += 1;
}
}
}
else
{
knockBackCounter -= Time.deltaTime;
}
}

public void Knockback(Vector3 direction)
{
knockBackCounter = knockBackTime;
anim.Play("Jump");
audioSource.PlayOneShot(HurtSound, 50F);
moveDirection = direction * knockBackForce;
moveDirection.y = knockBackForce;
}
}


It looks like it has to do with the verticalVelocity lines, but so far I have only tried setting verticalVelocity = 0 and that works until I have actually moved the character. What could I change to stop the flickering?










share|improve this question

























  • Add the code you are using to check if the player if grounded or not. There may be the issue.

    – Ignacio Alorre
    Nov 25 '18 at 7:33











  • I can determine if it is grounded or not by checking the animation parameter "isFalling". It does flicker rapidly.

    – ReignBeaux
    Nov 25 '18 at 22:17


















0















The grounded state for my character controller flickers on and off constantly at what seems to be every frame. From what I know, it's supposed to check if the player is grounded through player.isGrounded, but something else is moving it back up.



using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerCharacterController: MonoBehaviour {

static Animator anim;

public bool walking;

public GameObject playerModel, Hero;
//Transforms
public Transform playerCam, character, centerPoint;

private Vector3 moveDirection;

//character controller declaration
CharacterController player;

//Mouse Rotation
private float rotX, rotY;
//Mouse Y Position
public float mouseYPosition = 1f;
//Mouse Sensitivity
public float Sensitivity = 10f;
//Mouse Zoom
private float zoom;
public float zoomSpeed = 2;
//Clamping Zoom
public float zoomMin = -2f;
public float zoomMax = -10f;
public float rotationSpeed = 5f;
//Move Front Back left & Right
private float moveFB, moveLR;
//Movement Speed
public float Speed = 2f;
//Velocity of Gravity
public float verticalVelocity;
//Jump Distance
public float jumpDist = 5f;
//Multiple Jumps
int jumpTimes;
//To use with Dialogue Manager
public DialogueManager DiagM;

public AudioClip jumpSound;
public AudioClip HurtSound;
public AudioClip PunchSound;

AudioSource audioSource;

//knockback

public float knockBackForce;
public float knockBackTime;
private float knockBackCounter;


// Use this for initialization
void Start ()
{
//character controller
player = GameObject.Find("Player").GetComponent<CharacterController> ();

StartCoroutine(MyCoroutine(character));

anim = GetComponent<Animator>();

//mouse zoom
zoom = -3;
centerPoint.transform.position = playerCam.transform.position;
centerPoint.transform.parent = null;
audioSource = GetComponent<AudioSource>();
}

IEnumerator MyCoroutine (Transform character)
{
if (player.isGrounded == true)

{
anim.SetBool("isFalling",false);
//anim.SetBool("isIdling", true);
yield return new WaitForSeconds(0);
}

}
// Update is called once per frame

void Update ()
{
//Mouse Zoom Input
zoom += Input.GetAxis ("Mouse ScrollWheel") * zoomSpeed;

if (zoom > zoomMin)
zoom = zoomMin;
if (zoom < zoomMax)
zoom = zoomMax;

//Mouse Camera Input
playerCam.transform.localPosition = new Vector3 (0, 0, zoom);

//Mouse Rotation

rotX += Input.GetAxis ("Mouse X") * Sensitivity;
rotY -= Input.GetAxis ("Mouse Y") * Sensitivity;

//Clamp Camera
rotY = Mathf.Clamp (rotY, -60f, 60f);
playerCam.LookAt (centerPoint);
centerPoint.localRotation = Quaternion.Euler (rotY, rotX, 0);

//Movement Speed
if (knockBackCounter <= 0)
{
moveDirection = (transform.forward * Input.GetAxis("Vertical")) + (transform.right * Input.GetAxis("Horizontal"));
moveDirection = moveDirection * Speed;
moveDirection.y = verticalVelocity;

player.Move(moveDirection * Time.deltaTime);



//Movement Rotation

centerPoint.position = new Vector3 (character.position.x, character.position.y + mouseYPosition, character.position.z);

//knockback disable
//Movement Input

if (Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0)

{
transform.rotation = Quaternion.Euler(0f, centerPoint.rotation.eulerAngles.y, 0f);
Quaternion turnAngle = Quaternion.LookRotation(new Vector3(moveDirection.x, 0f, moveDirection.z));
playerModel.transform.rotation = Quaternion.Slerp(playerModel.transform.rotation, turnAngle, Time.deltaTime * rotationSpeed);

if (player.isGrounded == true)
{
anim.SetBool("isWalking", true);
anim.Play("Running");
}
}
else
{
StartCoroutine(MyCoroutine(character));
}

if (Input.GetButtonDown("LHand"))
{
audioSource.PlayOneShot(PunchSound, 1F);
anim.Play("RPunch");
}

if (player.isGrounded == true)
{
jumpTimes = 0;
//verticalVelocity = -Physics.gravity.y * Time.deltaTime;
verticalVelocity = 0;
}
else
{
verticalVelocity += Physics.gravity.y * Time.deltaTime;
anim.SetBool("isWalking", false);
anim.SetBool("isFalling", true);
}


if (jumpTimes < 1)
{
if (Input.GetButtonDown("Jump"))
{
verticalVelocity += jumpDist;
anim.Play("Jump");
audioSource.PlayOneShot(jumpSound, 1F);
jumpTimes += 1;
}
}
}
else
{
knockBackCounter -= Time.deltaTime;
}
}

public void Knockback(Vector3 direction)
{
knockBackCounter = knockBackTime;
anim.Play("Jump");
audioSource.PlayOneShot(HurtSound, 50F);
moveDirection = direction * knockBackForce;
moveDirection.y = knockBackForce;
}
}


It looks like it has to do with the verticalVelocity lines, but so far I have only tried setting verticalVelocity = 0 and that works until I have actually moved the character. What could I change to stop the flickering?










share|improve this question

























  • Add the code you are using to check if the player if grounded or not. There may be the issue.

    – Ignacio Alorre
    Nov 25 '18 at 7:33











  • I can determine if it is grounded or not by checking the animation parameter "isFalling". It does flicker rapidly.

    – ReignBeaux
    Nov 25 '18 at 22:17














0












0








0


0






The grounded state for my character controller flickers on and off constantly at what seems to be every frame. From what I know, it's supposed to check if the player is grounded through player.isGrounded, but something else is moving it back up.



using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerCharacterController: MonoBehaviour {

static Animator anim;

public bool walking;

public GameObject playerModel, Hero;
//Transforms
public Transform playerCam, character, centerPoint;

private Vector3 moveDirection;

//character controller declaration
CharacterController player;

//Mouse Rotation
private float rotX, rotY;
//Mouse Y Position
public float mouseYPosition = 1f;
//Mouse Sensitivity
public float Sensitivity = 10f;
//Mouse Zoom
private float zoom;
public float zoomSpeed = 2;
//Clamping Zoom
public float zoomMin = -2f;
public float zoomMax = -10f;
public float rotationSpeed = 5f;
//Move Front Back left & Right
private float moveFB, moveLR;
//Movement Speed
public float Speed = 2f;
//Velocity of Gravity
public float verticalVelocity;
//Jump Distance
public float jumpDist = 5f;
//Multiple Jumps
int jumpTimes;
//To use with Dialogue Manager
public DialogueManager DiagM;

public AudioClip jumpSound;
public AudioClip HurtSound;
public AudioClip PunchSound;

AudioSource audioSource;

//knockback

public float knockBackForce;
public float knockBackTime;
private float knockBackCounter;


// Use this for initialization
void Start ()
{
//character controller
player = GameObject.Find("Player").GetComponent<CharacterController> ();

StartCoroutine(MyCoroutine(character));

anim = GetComponent<Animator>();

//mouse zoom
zoom = -3;
centerPoint.transform.position = playerCam.transform.position;
centerPoint.transform.parent = null;
audioSource = GetComponent<AudioSource>();
}

IEnumerator MyCoroutine (Transform character)
{
if (player.isGrounded == true)

{
anim.SetBool("isFalling",false);
//anim.SetBool("isIdling", true);
yield return new WaitForSeconds(0);
}

}
// Update is called once per frame

void Update ()
{
//Mouse Zoom Input
zoom += Input.GetAxis ("Mouse ScrollWheel") * zoomSpeed;

if (zoom > zoomMin)
zoom = zoomMin;
if (zoom < zoomMax)
zoom = zoomMax;

//Mouse Camera Input
playerCam.transform.localPosition = new Vector3 (0, 0, zoom);

//Mouse Rotation

rotX += Input.GetAxis ("Mouse X") * Sensitivity;
rotY -= Input.GetAxis ("Mouse Y") * Sensitivity;

//Clamp Camera
rotY = Mathf.Clamp (rotY, -60f, 60f);
playerCam.LookAt (centerPoint);
centerPoint.localRotation = Quaternion.Euler (rotY, rotX, 0);

//Movement Speed
if (knockBackCounter <= 0)
{
moveDirection = (transform.forward * Input.GetAxis("Vertical")) + (transform.right * Input.GetAxis("Horizontal"));
moveDirection = moveDirection * Speed;
moveDirection.y = verticalVelocity;

player.Move(moveDirection * Time.deltaTime);



//Movement Rotation

centerPoint.position = new Vector3 (character.position.x, character.position.y + mouseYPosition, character.position.z);

//knockback disable
//Movement Input

if (Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0)

{
transform.rotation = Quaternion.Euler(0f, centerPoint.rotation.eulerAngles.y, 0f);
Quaternion turnAngle = Quaternion.LookRotation(new Vector3(moveDirection.x, 0f, moveDirection.z));
playerModel.transform.rotation = Quaternion.Slerp(playerModel.transform.rotation, turnAngle, Time.deltaTime * rotationSpeed);

if (player.isGrounded == true)
{
anim.SetBool("isWalking", true);
anim.Play("Running");
}
}
else
{
StartCoroutine(MyCoroutine(character));
}

if (Input.GetButtonDown("LHand"))
{
audioSource.PlayOneShot(PunchSound, 1F);
anim.Play("RPunch");
}

if (player.isGrounded == true)
{
jumpTimes = 0;
//verticalVelocity = -Physics.gravity.y * Time.deltaTime;
verticalVelocity = 0;
}
else
{
verticalVelocity += Physics.gravity.y * Time.deltaTime;
anim.SetBool("isWalking", false);
anim.SetBool("isFalling", true);
}


if (jumpTimes < 1)
{
if (Input.GetButtonDown("Jump"))
{
verticalVelocity += jumpDist;
anim.Play("Jump");
audioSource.PlayOneShot(jumpSound, 1F);
jumpTimes += 1;
}
}
}
else
{
knockBackCounter -= Time.deltaTime;
}
}

public void Knockback(Vector3 direction)
{
knockBackCounter = knockBackTime;
anim.Play("Jump");
audioSource.PlayOneShot(HurtSound, 50F);
moveDirection = direction * knockBackForce;
moveDirection.y = knockBackForce;
}
}


It looks like it has to do with the verticalVelocity lines, but so far I have only tried setting verticalVelocity = 0 and that works until I have actually moved the character. What could I change to stop the flickering?










share|improve this question
















The grounded state for my character controller flickers on and off constantly at what seems to be every frame. From what I know, it's supposed to check if the player is grounded through player.isGrounded, but something else is moving it back up.



using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerCharacterController: MonoBehaviour {

static Animator anim;

public bool walking;

public GameObject playerModel, Hero;
//Transforms
public Transform playerCam, character, centerPoint;

private Vector3 moveDirection;

//character controller declaration
CharacterController player;

//Mouse Rotation
private float rotX, rotY;
//Mouse Y Position
public float mouseYPosition = 1f;
//Mouse Sensitivity
public float Sensitivity = 10f;
//Mouse Zoom
private float zoom;
public float zoomSpeed = 2;
//Clamping Zoom
public float zoomMin = -2f;
public float zoomMax = -10f;
public float rotationSpeed = 5f;
//Move Front Back left & Right
private float moveFB, moveLR;
//Movement Speed
public float Speed = 2f;
//Velocity of Gravity
public float verticalVelocity;
//Jump Distance
public float jumpDist = 5f;
//Multiple Jumps
int jumpTimes;
//To use with Dialogue Manager
public DialogueManager DiagM;

public AudioClip jumpSound;
public AudioClip HurtSound;
public AudioClip PunchSound;

AudioSource audioSource;

//knockback

public float knockBackForce;
public float knockBackTime;
private float knockBackCounter;


// Use this for initialization
void Start ()
{
//character controller
player = GameObject.Find("Player").GetComponent<CharacterController> ();

StartCoroutine(MyCoroutine(character));

anim = GetComponent<Animator>();

//mouse zoom
zoom = -3;
centerPoint.transform.position = playerCam.transform.position;
centerPoint.transform.parent = null;
audioSource = GetComponent<AudioSource>();
}

IEnumerator MyCoroutine (Transform character)
{
if (player.isGrounded == true)

{
anim.SetBool("isFalling",false);
//anim.SetBool("isIdling", true);
yield return new WaitForSeconds(0);
}

}
// Update is called once per frame

void Update ()
{
//Mouse Zoom Input
zoom += Input.GetAxis ("Mouse ScrollWheel") * zoomSpeed;

if (zoom > zoomMin)
zoom = zoomMin;
if (zoom < zoomMax)
zoom = zoomMax;

//Mouse Camera Input
playerCam.transform.localPosition = new Vector3 (0, 0, zoom);

//Mouse Rotation

rotX += Input.GetAxis ("Mouse X") * Sensitivity;
rotY -= Input.GetAxis ("Mouse Y") * Sensitivity;

//Clamp Camera
rotY = Mathf.Clamp (rotY, -60f, 60f);
playerCam.LookAt (centerPoint);
centerPoint.localRotation = Quaternion.Euler (rotY, rotX, 0);

//Movement Speed
if (knockBackCounter <= 0)
{
moveDirection = (transform.forward * Input.GetAxis("Vertical")) + (transform.right * Input.GetAxis("Horizontal"));
moveDirection = moveDirection * Speed;
moveDirection.y = verticalVelocity;

player.Move(moveDirection * Time.deltaTime);



//Movement Rotation

centerPoint.position = new Vector3 (character.position.x, character.position.y + mouseYPosition, character.position.z);

//knockback disable
//Movement Input

if (Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0)

{
transform.rotation = Quaternion.Euler(0f, centerPoint.rotation.eulerAngles.y, 0f);
Quaternion turnAngle = Quaternion.LookRotation(new Vector3(moveDirection.x, 0f, moveDirection.z));
playerModel.transform.rotation = Quaternion.Slerp(playerModel.transform.rotation, turnAngle, Time.deltaTime * rotationSpeed);

if (player.isGrounded == true)
{
anim.SetBool("isWalking", true);
anim.Play("Running");
}
}
else
{
StartCoroutine(MyCoroutine(character));
}

if (Input.GetButtonDown("LHand"))
{
audioSource.PlayOneShot(PunchSound, 1F);
anim.Play("RPunch");
}

if (player.isGrounded == true)
{
jumpTimes = 0;
//verticalVelocity = -Physics.gravity.y * Time.deltaTime;
verticalVelocity = 0;
}
else
{
verticalVelocity += Physics.gravity.y * Time.deltaTime;
anim.SetBool("isWalking", false);
anim.SetBool("isFalling", true);
}


if (jumpTimes < 1)
{
if (Input.GetButtonDown("Jump"))
{
verticalVelocity += jumpDist;
anim.Play("Jump");
audioSource.PlayOneShot(jumpSound, 1F);
jumpTimes += 1;
}
}
}
else
{
knockBackCounter -= Time.deltaTime;
}
}

public void Knockback(Vector3 direction)
{
knockBackCounter = knockBackTime;
anim.Play("Jump");
audioSource.PlayOneShot(HurtSound, 50F);
moveDirection = direction * knockBackForce;
moveDirection.y = knockBackForce;
}
}


It looks like it has to do with the verticalVelocity lines, but so far I have only tried setting verticalVelocity = 0 and that works until I have actually moved the character. What could I change to stop the flickering?







c# unity3d unityscript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 7:22









Ignacio Alorre

3,32342953




3,32342953










asked Nov 24 '18 at 22:50









ReignBeauxReignBeaux

378




378













  • Add the code you are using to check if the player if grounded or not. There may be the issue.

    – Ignacio Alorre
    Nov 25 '18 at 7:33











  • I can determine if it is grounded or not by checking the animation parameter "isFalling". It does flicker rapidly.

    – ReignBeaux
    Nov 25 '18 at 22:17



















  • Add the code you are using to check if the player if grounded or not. There may be the issue.

    – Ignacio Alorre
    Nov 25 '18 at 7:33











  • I can determine if it is grounded or not by checking the animation parameter "isFalling". It does flicker rapidly.

    – ReignBeaux
    Nov 25 '18 at 22:17

















Add the code you are using to check if the player if grounded or not. There may be the issue.

– Ignacio Alorre
Nov 25 '18 at 7:33





Add the code you are using to check if the player if grounded or not. There may be the issue.

– Ignacio Alorre
Nov 25 '18 at 7:33













I can determine if it is grounded or not by checking the animation parameter "isFalling". It does flicker rapidly.

– ReignBeaux
Nov 25 '18 at 22:17





I can determine if it is grounded or not by checking the animation parameter "isFalling". It does flicker rapidly.

– ReignBeaux
Nov 25 '18 at 22:17












1 Answer
1






active

oldest

votes


















0














As per you comment. You should not determine if your player is grounded by checking an animation parameter. The best way is to use a RayCast(). So what you have to do:




  1. Create a Layer named Ground, and add all the platforms in your
    scene to that layer.

  2. Create a bool variable


i.e



bool isGrounded;



  1. Create a function to check if the character is grounded


Something like:



bool checkGrounded(){

return Physics.Raycast(transform.position, Vector3.down, 2f, 1 << LayerMask.NameToLayer("Ground")));

}


In this answer you can read about the involved parameters in the Raycast




  1. Finally inside the update check if the player is grounded or not


Something like:



void Update(){
isGrounded = checkGrounded();
}





share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53463043%2funity-grounded-state-is-flickering-for-character-isgrounded-being-used-but-sti%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    As per you comment. You should not determine if your player is grounded by checking an animation parameter. The best way is to use a RayCast(). So what you have to do:




    1. Create a Layer named Ground, and add all the platforms in your
      scene to that layer.

    2. Create a bool variable


    i.e



    bool isGrounded;



    1. Create a function to check if the character is grounded


    Something like:



    bool checkGrounded(){

    return Physics.Raycast(transform.position, Vector3.down, 2f, 1 << LayerMask.NameToLayer("Ground")));

    }


    In this answer you can read about the involved parameters in the Raycast




    1. Finally inside the update check if the player is grounded or not


    Something like:



    void Update(){
    isGrounded = checkGrounded();
    }





    share|improve this answer




























      0














      As per you comment. You should not determine if your player is grounded by checking an animation parameter. The best way is to use a RayCast(). So what you have to do:




      1. Create a Layer named Ground, and add all the platforms in your
        scene to that layer.

      2. Create a bool variable


      i.e



      bool isGrounded;



      1. Create a function to check if the character is grounded


      Something like:



      bool checkGrounded(){

      return Physics.Raycast(transform.position, Vector3.down, 2f, 1 << LayerMask.NameToLayer("Ground")));

      }


      In this answer you can read about the involved parameters in the Raycast




      1. Finally inside the update check if the player is grounded or not


      Something like:



      void Update(){
      isGrounded = checkGrounded();
      }





      share|improve this answer


























        0












        0








        0







        As per you comment. You should not determine if your player is grounded by checking an animation parameter. The best way is to use a RayCast(). So what you have to do:




        1. Create a Layer named Ground, and add all the platforms in your
          scene to that layer.

        2. Create a bool variable


        i.e



        bool isGrounded;



        1. Create a function to check if the character is grounded


        Something like:



        bool checkGrounded(){

        return Physics.Raycast(transform.position, Vector3.down, 2f, 1 << LayerMask.NameToLayer("Ground")));

        }


        In this answer you can read about the involved parameters in the Raycast




        1. Finally inside the update check if the player is grounded or not


        Something like:



        void Update(){
        isGrounded = checkGrounded();
        }





        share|improve this answer













        As per you comment. You should not determine if your player is grounded by checking an animation parameter. The best way is to use a RayCast(). So what you have to do:




        1. Create a Layer named Ground, and add all the platforms in your
          scene to that layer.

        2. Create a bool variable


        i.e



        bool isGrounded;



        1. Create a function to check if the character is grounded


        Something like:



        bool checkGrounded(){

        return Physics.Raycast(transform.position, Vector3.down, 2f, 1 << LayerMask.NameToLayer("Ground")));

        }


        In this answer you can read about the involved parameters in the Raycast




        1. Finally inside the update check if the player is grounded or not


        Something like:



        void Update(){
        isGrounded = checkGrounded();
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 26 '18 at 7:06









        Ignacio AlorreIgnacio Alorre

        3,32342953




        3,32342953
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53463043%2funity-grounded-state-is-flickering-for-character-isgrounded-being-used-but-sti%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()