-
-
Save bendux/5fab0c176855d4e37bf6a38bb071b4a4 to your computer and use it in GitHub Desktop.
using UnityEngine; | |
public class PlayerMovement : MonoBehaviour | |
{ | |
private float horizontal; | |
private float speed = 8f; | |
private float jumpingPower = 16f; | |
private bool isFacingRight = true; | |
[SerializeField] private Rigidbody2D rb; | |
[SerializeField] private Transform groundCheck; | |
[SerializeField] private LayerMask groundLayer; | |
void Update() | |
{ | |
horizontal = Input.GetAxisRaw("Horizontal"); | |
if (Input.GetButtonDown("Jump") && IsGrounded()) | |
{ | |
rb.velocity = new Vector2(rb.velocity.x, jumpingPower); | |
} | |
if (Input.GetButtonUp("Jump") && rb.velocity.y > 0f) | |
{ | |
rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f); | |
} | |
Flip(); | |
} | |
private void FixedUpdate() | |
{ | |
rb.velocity = new Vector2(horizontal * speed, rb.velocity.y); | |
} | |
private bool IsGrounded() | |
{ | |
return Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer); | |
} | |
private void Flip() | |
{ | |
if (isFacingRight && horizontal < 0f || !isFacingRight && horizontal > 0f) | |
{ | |
isFacingRight = !isFacingRight; | |
Vector3 localScale = transform.localScale; | |
localScale.x *= -1f; | |
transform.localScale = localScale; | |
} | |
} | |
} |
I followed the entire tutorial and got everything working but the jump button is not working so unless the jump button is some weird button i would never think to press im confused. I dont have discord so i cant talk on there
So you need help right, ask chat gpt.
Hippity Hoppity, thank you for your Coditty <3
you said it wrong
hippity hoppity your code is now my property.
Hippity Hoppity Thank you you help me in my game journey
Hippity hopity you code is now my property
Hippity hopity your code is now my property (thx)
i think im doing it wrong but it keeps giving me errors
@CalculatedChaos44 Join our Discord server, and let's solve your problem together!
It's not working, I can't jump for some reason
@HydroniumCore Make sure that the ground check is positioned on the bottom edge of your player's collider.
i keep getting errors saying that rb is not defined
HELP i can do everything and yeah everything is fine EXCEPT that i cant FRICKING JUMP (pls help)
(edit i kept messing with everything until i saw that ground check is not available...)
@MasterZombieYT What do you mean?
hipitiy hoppity your code is now my property
your, dont you mean "OUR"
eyyyyy bois wanna steal the fricking code? CUZ HIPPITY HOPPITY ITS MY PROPRTEY BITCH >:)
eyyyyy bois want to steal the fricking code? BECAUSE HIPPITY HOPPITY ITS MY PROPERTY BITCH >:)
The movement works, but it wont jump, I'm not sure what the problem is
add a rigidbody
Is there a way I could get a hold of a working combination of the scripts: Movement, Double Jump, Wall Jump and Slide, and Dash by Bendux? I am just starting my Gaming Development Career and am not good at coding with C# yet I can not find anything that works and don't know how to combine them on my own. Thanks!
Is there a way I could get a hold of a working combination of the scripts: Movement, Double Jump, Wall Jump and Slide, and Dash by Bendux? I am just starting my Gaming Development Career and am not good at coding with C# yet I can not find anything that works and don't know how to combine them on my own. Thanks!
im doing the same, have you found out?
okay thanks a lot!
okay thanks a lot!
Here is the code sorry it took so long
https://gist.github.com/Pixel8tedPotato/ead41c9381b11ce47a3833fdc1198193
Shouldn't the jump be in fixedupdate()?
i can't jump
@gavyeah You probably skipped one or two important steps in the tutorial.
HELP i can do everything and yeah everything is fine EXCEPT that i cant FRICKING JUMP (pls help) (edit i kept messing with everything until i saw that ground check is not available...)
HOW ON EARTH DO YOU JUMP!!!!!!!!
I cant jump i have checked everything and it still wont work someone help
update: I got jumping to work by setting the groundcheck to have a layer if ground and also adding a box colider 2D
the only problem is that it jumps mid air and you can pretty much just fly, I dont know how to fix it
I followed the entire tutorial and got everything working but the jump button is not working so unless the jump button is some weird button i would never think to press im confused. I dont have discord so i cant talk on there