I'm working on a very basic side scrolling platformer in Unity 3D. The player is a cube, you can move left and right, you can jump. I can't get the movement correct as the character moves too slow.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public float walkSpeed = 15f;
public float jumpSpeed = 15f;
public float gravity = 50f;
Rigidbody rb;
bool pressedJump = false;
Vector3 movementInput;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
movementInput = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
}
void FixedUpdate()
{
WalkHandler();
JumpHandler();
GravityHandler();
}
void WalkHandler()
{
rb.velocity = new Vector2(0f, rb.velocity.y);
rb.velocity = movementInput * walkSpeed * Time.fixedDeltaTime;
}
void JumpHandler()
{
if (Input.GetButtonDown("Jump"))
{
if (!pressedJump)
{
pressedJump = true;
Vector3 jumpVector = new Vector3(0f, jumpSpeed, 0f);
rb.velocity = rb.velocity + jumpVector;
}
}
else
{
pressedJump = false;
}
}
void GravityHandler()
{
rb.AddForce(Vector3.down * gravity * rb.mass);
}
}
More context I originally had this implemented and it worked. Very smooth movement and jumping. I tragically lost that game due to my own actions. So I'm trying to recreate it. Here is a video of the original movement and jumping I'm looking to recreate:
Note: The values for walkSpeed, jumpForce and gravity were what was used previously.
Losing the first game was pretty soul crushing so any help would be great.
walkSpeedin the inspector while you play? - Daniel