Answer the question
In order to leave comments, you need to log in
How to fix jump error?
Hello! I made controls for the character, everything works, but the jump is endless, and I don’t know what to do, although I seem to have set everything up correctly. Throws an error: "UnassignedReferenceException: The variable feetPos of HeroCntrl has not been assigned.
You probably need to assign the feetPos variable of the HeroCntrl script in the inspector." I put feetPos under the character, and highlight it in green, in the editor I put it under my feet, I select everything for all objects (Ground), but still there is such a problem. Please help me fix the error!
Here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HeroCntrl : MonoBehaviour
{
public float speed = 10f;
public float jumpForce;
private float moveInput;
Rigidbody2D rb;
private bool FacingRight = false;
private bool isGrounded;
public Transform feetPos;
public float checkRadius;
public LayerMask WhatIsGround;
private void Start()
{
rb = GetComponent<Rigidbody2D>();
}
private void Update()
{
isGrounded = Physics2D.OverlapCircle(feetPos.position, checkRadius, WhatIsGround);
if (isGrounded = true && Input.GetKeyDown(KeyCode.Space))
{
rb.velocity = Vector2.up * jumpForce;
}
}
private void FixedUpdate()
{
moveInput = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
if (FacingRight = false && moveInput > 0)
{
Flip();
}
else if (FacingRight = true && moveInput < 0)
{
Flip();
}
}
void Flip()
{
FacingRight = !FacingRight;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
}
Answer the question
In order to leave comments, you need to log in
In this course that you are doing, he says a hundred times why this can be.
In general, I advise you not to go through it, there are a lot of blunts)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question