AccountError
Banned
-
- Joined
- Feb 24, 2020
- Posts
- 5,546
@RemoveNormalfags
What has happened so far is that I've made a script for the player to move left, right, including a jump button. Some lines are irrelevant as I plan to use them in the future. The application shows 0 errors but the script does not work upon testing it out, during the earlier versions of the code the player was able to move around, but as soon as I implemented the ability to jump it's stopped working. Posting here cos too long for a reply
What has happened so far is that I've made a script for the player to move left, right, including a jump button. Some lines are irrelevant as I plan to use them in the future. The application shows 0 errors but the script does not work upon testing it out, during the earlier versions of the code the player was able to move around, but as soon as I implemented the ability to jump it's stopped working. Posting here cos too long for a reply
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class movebasic : MonoBehaviour {
private Rigidbody2D rb;
private bool isFacingRight = true;
private float movementInputDirection;
public float movementspeed = 10.0f;
public float jumpForce = 16.0f;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
CheckInput();
CheckMovementDirection();
}
private void FixedUpdate()
{
ApplyMovement();
}
private void CheckMovementDirection()
{
if(isFacingRight && movementInputDirection < 0)
{
Flip();
}
else if(isFacingRight && movementInputDirection > 0)
{
Flip();
}
}
private void CheckInput()
{
movementInputDirection = Input.GetAxisRaw("Horizontal");
{
if (Input.GetButtonDown("jump"))
{
Jump();
}
}
}
private void Jump()
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
}
private void ApplyMovement()
private void Flip()
{ {
rb.velocity = new Vector2(movementspeed * movementInputDirection, rb.velocity.y);
}
isFacingRight = !isFacingRight;
transform.Rotate(0.0f, 100.0f, 0.0f);
}
}





