Question by
TowaloToby · Sep 15, 2020 at 09:43 PM ·
2dmovementplatformercrouching
Can't move while crouched
Hey, I'm building a platformer App for the smartphone and therefore have a joystick for horizontal Movement, jumping and crouching. The Problem is, that I can't move horizontally while crouched. If anyone can help me or correct the code, I'll write it underneath my question. Since I'm quite new to Unity and c#, I appreciate your help!
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public CharacterController2D controller;
public float runSpeed = 40f;
public Joystick Joystick;
float horizontalMove = 0f;
bool jump = false;
bool crouch = false;
void Update()
{
horizontalMove = Joystick.Horizontal * runSpeed;
float verticalMove = Joystick.Vertical;
if (verticalMove >= .5f)
{
jump = true;
}
if (verticalMove <= -.5f)
{
crouch = true;
}
else
{
crouch = false;
}
}
void FixedUpdate()
{
controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
jump = false;
}
}
Comment