-
-
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; | |
} | |
} | |
} |
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
*SWIPE~
add a rigidbody