Kaelen
Kaelen
CC#
Created by Kaelen on 5/30/2023 in #help
❔ Nav Mesh Agent doesnt avoid obstacles
9 replies
CC#
Created by Kaelen on 4/18/2023 in #help
❔ Animation never stop c#
Hey, I have an animation on my character, and when I'm starting walking, my character my game doesnt stop the animation, here is myy code :
public class PlayerMovement : MonoBehaviour
{
float speed = 4;
private CharacterController controller;
private Vector3 direction;
private Vector2 move;
private float gravity = 9.81f;
public static float velocity;
private string WALK_ANIMATION = "Walk";
private Animator anim;
PlayerInput input;
private Vector2 currentMovement;
private bool movementPressed;

void OnMove(InputValue value){
move = value.Get<Vector2>();

}

void Awake(){
input = new PlayerInput();
}

void handleMovement() {
input.Player.Move.performed += ctx => {
currentMovement = ctx.ReadValue<Vector2>();
movementPressed = currentMovement.x != 0 || currentMovement.y != 0;
};

bool isWalking = anim.GetBool(WALK_ANIMATION);
if(movementPressed && !isWalking){
anim.SetBool(WALK_ANIMATION, true);
}
if(!movementPressed && isWalking){
anim.SetBool(WALK_ANIMATION, false);
}

Debug.Log(anim.GetBool(WALK_ANIMATION));
Debug.Log(currentMovement);
}

// Start is called before the first frame update
void Start()
{
anim = GetComponent<Animator>();
controller = GetComponent<CharacterController>();
}

// Update is called once per frame
void Update()
{

if(!controller.isGrounded){
velocity += gravity * Time.deltaTime;
}

direction = new Vector3(move.x, velocity, move.y);
controller.Move(-direction * speed * Time.deltaTime);
handleMovement();

}

void OnEnable(){
input.Player.Enable();
}

void OnDisable(){
input.Player.Disable();
}


}
public class PlayerMovement : MonoBehaviour
{
float speed = 4;
private CharacterController controller;
private Vector3 direction;
private Vector2 move;
private float gravity = 9.81f;
public static float velocity;
private string WALK_ANIMATION = "Walk";
private Animator anim;
PlayerInput input;
private Vector2 currentMovement;
private bool movementPressed;

void OnMove(InputValue value){
move = value.Get<Vector2>();

}

void Awake(){
input = new PlayerInput();
}

void handleMovement() {
input.Player.Move.performed += ctx => {
currentMovement = ctx.ReadValue<Vector2>();
movementPressed = currentMovement.x != 0 || currentMovement.y != 0;
};

bool isWalking = anim.GetBool(WALK_ANIMATION);
if(movementPressed && !isWalking){
anim.SetBool(WALK_ANIMATION, true);
}
if(!movementPressed && isWalking){
anim.SetBool(WALK_ANIMATION, false);
}

Debug.Log(anim.GetBool(WALK_ANIMATION));
Debug.Log(currentMovement);
}

// Start is called before the first frame update
void Start()
{
anim = GetComponent<Animator>();
controller = GetComponent<CharacterController>();
}

// Update is called once per frame
void Update()
{

if(!controller.isGrounded){
velocity += gravity * Time.deltaTime;
}

direction = new Vector3(move.x, velocity, move.y);
controller.Move(-direction * speed * Time.deltaTime);
handleMovement();

}

void OnEnable(){
input.Player.Enable();
}

void OnDisable(){
input.Player.Disable();
}


}
5 replies
CC#
Created by Kaelen on 1/1/2023 in #help
❔ My Raycast seems to be upside down
32 replies
CC#
Created by Kaelen on 12/31/2022 in #help
✅ [RESOLVED]It seems that my variables is destroyed after the Awake()
4 replies