Question by
scarletcircle · Apr 22, 2020 at 09:55 AM ·
c#animationscripting problemanimatormovement script
Help please, movement and animator issue
Hi guys, so i am working on testing animator with a c# code lines in aim to move the character while being animated in an attractive way, however, whenever i push play button on unity the only animation played is idle position, furthermore, i cannot move right nor left, or jump, knowing that i already integrated the whole script so my character will do so. help please.
![alt text][1]using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerController : MonoBehaviour
{
public float jumpForce;
public float speed;
private Rigidbody2D rb;
public Transform groundPos;
private bool isGrounded;
public float checkRadius;
public LayerMask whatIsGround;
private float jumpTimeCounter;
public float jumpTime;
private bool isJumping;
private bool doubleJump;
private Animator anim;
private void Start()
{
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody2D>();
}
private void update()
{
isGrounded = Physics2D.OverlapCircle(groundPos.position, checkRadius, whatIsGround);
if (isGrounded == true && Input.GetKeyDown(KeyCode.Z))
{
anim.SetTrigger("takeOf");
isJumping = true;
jumpTimeCounter = jumpTime;
rb.velocity = Vector2.up * jumpForce;
}
if (isGrounded == true)
{
doubleJump = false;
anim.SetBool("isJumping", false);
}
else {
anim.SetBool("isJumping", true);
}
if (Input.GetKey(KeyCode.Z) && isJumping == true)
{
if (jumpTimeCounter > 0)
{
rb.velocity = Vector2.up * jumpForce;
jumpTimeCounter -= Time.deltaTime;
}
else
{
isJumping = false;
}
}
if (Input.GetKeyUp(KeyCode.Z))
{
isJumping = false;
}
if (isGrounded == false && doubleJump == false && Input.GetKeyDown(KeyCode.Z)) {
isJumping = true;
doubleJump = true;
isJumping = true;
jumpTimeCounter = jumpTime;
rb.velocity = Vector2.up * jumpForce;
}
float moveInput = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
if (moveInput == 0) {
anim.SetBool("isRunning", false);
}
if (moveInput < 0)
{
transform.eulerAngles = new Vector3(0, 180, 0);
}
else if (moveInput > 0)
{
transform.eulerAngles = new Vector3(0, 0, 0);
}
}
}**
[1]: /storage/temp/157273-screen-shot-2020-04-21-at-70223-pm.png
screen-shot-2020-04-21-at-70223-pm.png
(68.2 kB)
Comment
Your answer
Follow this Question
Related Questions
Movement and Jump with animator 0 Answers
animator and script issue 0 Answers
When I run this code Unity crashes(ANIMATOR RELATED) 0 Answers
How do I make my attack trigger work? 1 Answer
ANIMATION STRANGELY DOES NOT PLAY 0 Answers