Salto do jogador | Plataforma 2D em Unity #3 | Tutorial de desenvolvimento de jogos 2D

Aprenda a fazer um jogo de plataforma 2D no Unity. Neste vídeo, analisamos a criação de um script Player Jump no Unity que usa Colliders para verificar se o jogador está no chão antes de pular. Um tutorial de desenvolvimento de jogos Unity 2D. Obrigado por assistir! Twitter: https://twitter.com/tyler_potts_ Confira meu canal principal: https://youtube.com/c/tylerpotts Aspiro ser um desenvolvedor de jogos independente fazendo jogos divertidos e imersivos. Eu me concentro no desenvolvimento de jogos 2D Unity. #GameDev #IndieGameDev #Unity2D #KeepMuddy
source
vector2 isn't a method for me I have visual studio. I get this error when I press space to jump
UnassignedReferenceException: The variable feet of PlayerMovement has not been assigned.
You probably need to assign the feet variable of the PlayerMovement script in the inspector.
UnityEngine.Transform.get_position () (at <ca42919df2b74e53b11002749c8755af>:0)
PlayerMovement.IsGrounded () (at Assets/Scripts/PlayerMovement.cs:42)
PlayerMovement.Update () (at Assets/Scripts/PlayerMovement.cs:20)
Any ideas would be much appreciated
how do i get rid of the spam jump up the wall glitch?
WHY DOES EVERYONE MAKE UNNECESSARILY COMPLICATED CHARACTER CONTROLLERS
My console says that I need to set up an input button
I don’t know if you’re still replying but can someone please help, so the problem is once I finished the script for this part every time I walk off a platform without jumping I rotate and I can’t jump anymore.
pls help by telling me my mistakes because I can't jump:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public float movementSpeed;
public Rigidbody2D rb;
public float jumpForce = 20f;
public Transform feet;
public LayerMask groundLayers;
float mx;
private void Update()
{
mx = Input.GetAxisRaw("Horizontal");
if (Input.GetButtonDown("Jump") && IsGrounded()) {
Jump();
}
}
private void FixedUpdate()
{
Vector2 movement = new Vector2(mx * movementSpeed, rb.velocity.y);
rb.velocity = movement;
}
void Jump() {
Vector2 movement = new Vector2(rb.velocity.x, jumpForce);
rb.velocity = movement;
}
public bool IsGrounded() {
Collider2D groundCheck = Physics2D.OverlapCircle(feet.position, 0.5f, groundLayers);
if (groundCheck != null) {
return true;
}
return false;
}
}
If your player won't jump after it's flipped on one side, here's how to fix it:
First, in the PlayerMovement script, create a float-type variable above the "private void Update() {" line. The variable should be called "lockPos" and set to 0. Here's how it looks:
float lockPos = 0; (put that above the "private void Update" line)
After that, under the "private void Update() {" line, copy and paste this:
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, lockPos, lockPos);
If that doesn't fix the bug, or you're just confused, please let me know. 😀
I love it
I love it
I love it
I love it
I love it
I love it
thank you so much
Good tutorial, but it would have been nice for you to say what any of the keywords and functions actually do. Found myself just typing out a copy of your code and thinking "yep. Not a clue what .velocity does, or .OverlapCircle2D()"
When I move, I just jump once, isn't there a way to make it jump continuously while I am moving?
it gives me error that groundLayer does not exist
DUDE MY PLAYER JUMPS OF THE CAMERA HELP HE JUMPS SO HIGH
hello sir i have a question why if i change the size of my box collider 2D my player cant jump anymore?
can someone please explain why you add and f after the 20 in jumpForce
I can’t jump help
for people wondering why their sprite doesnt jump remember your sprite may be a different size to his so you need to set the tile postion for y where it touches the ground
After I added the script that would limit on how many jumps you can do before you hit the ground, it would let me jump at all and would just constantly put 100+ erors in my console ever second. I'm not sure what to do
if anyone could help me I would appriciate it
"so if we are grounded we can jump"
People who are grounded by their parents for 2 weeks: I BELIEVE I CAN FLY
my return and if is pink
idk what to do
if you can still jump in the air, here is a fix. Put the feet onto the bottom of the player (so instead of 0.5, put in -0.5) then put the player as another layer, the reason why is that the feet think that the player is a ground (since it is classified as a ground in the layers tab) and continuously jump. If you need any help, text me on discord and I can send pictures. Aksumite#1726
Anyone who wants this for 3d games
using UnityEngine;
public class MoveCube : MonoBehaviour
{
private const string AxisName = "Horizontal";
public float speed = .1f;
public Rigidbody rb;
public float JumpForce = 20f;
public Transform Feet;
public LayerMask groundLayers;
public int CanJump;
void Update()
{
float xDirection = Input.GetAxis(AxisName);
float zDirection = Input.GetAxis("Vertical");
Vector3 moveDirection = new Vector3(xDirection, 0.0f, zDirection);
transform.position += moveDirection * speed;
if (Input.GetKeyDown(KeyCode.Space))
{
Jump();
}
}
void Jump()
{
if (CanJump > 0)
{
Vector3 movement = new Vector2(rb.velocity.x, JumpForce);
rb.velocity = movement;
}
}
public void OnCollisionEnter(Collision collision)
{
CanJump = 1;
}
public void OnCollisionExit(Collision collision)
{
CanJump = 0;
}
}
2:54 saving for myself ignore