Hello,
I am making a simple EASY and yes trying to make it easy 2d mobile android game for fun/test, but i got the run right and left working with button, but jumping, doesnt work, i looked at all tutorials online, youtube etc., they point to the same way or similiar way of jumping:
rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * jumpForce);
HOWEVER, my character never jumps, i even checked the gravity, i put debug.log() to test if the button is pressed, jump, YUP that works, however the character never jumps, i used brackeys, and other tutorials to help me get this working, but NOTHING!!! i am at my wits end with unity… i am willing to share my entire project to help assist on finding out what am i doing wrong š any help, suggestions etc… i will copy and paste the code, but i believe if i share my project, it will bring more light to the problem, please give me email if interested so i can email you the entire project, its about 79 mb zipped file.
below is the CharacterControls.cs i have attached to the character object to jump, i have rigidbody2d already set and collider, plus the GameObject that is invisible set as well to see if it has touched the ground. and yes i set that layer as well.
please… again i am at my wits end and wondering if unity is even good to make mobile games or should i try coco or godot for mobile games?
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityStandardAssets.CrossPlatformInput; public class CharacterControl : MonoBehaviour { float dirX; public float moveSpeed = 10f; Rigidbody2D rb; bool facingRight = true; Vector3 localScale; public Animator animator; private bool isGrounded = false; public Transform groundCheck; public float groundCheckRadius; public LayerMask whatIsGround; private bool jump = false; public float jumpForce; // Use this for initialization void Start () { localScale = transform.localScale; rb = GetComponent<Rigidbody2D> (); } // Update is called once per frame void Update() { dirX = CrossPlatformInputManager.GetAxis ("Horizontal"); isGrounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, whatIsGround); if(isGrounded && jump == true) { //rb.velocity = Vector2.up * jumpForce; rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * jumpForce); } } void FixedUpdate() { rb.velocity = new Vector2 (dirX * moveSpeed, 0); if (rb.velocity.magnitude > 0) { animator.SetBool("Run", true); } else animator.SetBool("Run", false); } void LateUpdate() { CheckWhereToFace (); } public void JumpCheck(bool checkjump) { if (checkjump == true) { jump = true; } } void CheckWhereToFace () { if (dirX > 0) facingRight = true; else if (dirX < 0) facingRight = false; if (((facingRight) && (localScale.x < 0)) || ((!facingRight) && (localScale.x > 0))) { localScale.x *= -1; } transform.localScale = localScale; } }