- Home /
Question by
Ronanator · Jun 11, 2021 at 07:58 PM ·
3dcharactercontrollerplatformer
Character controller stopping.
So I'm creating a 3d platformer and for some reason when I want to jump off a wall it applies the motion but stops half a second later I don't know what is the cause of the issue it may have something to do with my other movement but I don't want to disable it because I want the player to have full control in the air. (also my code may be a mess I'm trying to fix it)
Thanks
public class CharacterControls : MonoBehaviour
{
// Animator.
public Animator anim;
// Inputs.
public InputActionReference movementControl;
public InputActionReference UpDownControl;
// character controllers
public CharacterController controller;
public MovingPlatForm ExternalMove;
// Other Files.
public WallJumpBoxCheck wallchecks;
// Movement..
[SerializeField] private float speed = 10;
//Facing.
bool directionFacing;
public Transform character;
// controls ground identifyers
public bool isGrounded;
public float groundDistance = 0.4f;
public LayerMask groundMask;
public Transform groundCheck;
// Controls.
public Vector3 playerVelocity;
public Vector3 move;
// Jump + Double jump.
public float playeraction;
public bool isjumping;
public bool isWalljumping = false;
[SerializeField] private float jumpSpeed = 10;
public float gravityValue = -9.81f;
public float wallJumpSpeed;
public float cooldownTime;
public float nextFireTime;
public float wallCooldownTime;
public float wallNextFireTime;
// Camera.
public Transform cameraMain;
public void OnEnable()
{
movementControl.action.Enable();
UpDownControl.action.Enable();
}
public void OnDisable()
{
movementControl.action.Disable();
UpDownControl.action.Disable();
}
// Start is called before the first frame update
void Start()
{
controller = gameObject.GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
// check if player is close to the ground and return true if player is.
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
anim.SetBool("isgrounded", isGrounded);
// action to control the jump
playeraction = UpDownControl.action.ReadValue<float>();
// action to control the movement
float movementInput = movementControl.action.ReadValue<float>();
// convert movement input to vector 3
move = new Vector3(movementInput , 0, 0);
// Apply Movement.
move.y = 0;
controller.Move(move * Time.deltaTime * speed);
anim.SetFloat("Speed", move.x);
if (isGrounded)
{
anim.SetBool("isJumped", false);
playerVelocity.y = -2f;
isWalljumping = false;
isjumping = false;
}
//jump
// check if player is grounded and presses up
if (isGrounded && playeraction == 1)
{
// start timer
nextFireTime = Time.time + cooldownTime;
anim.SetBool("isJumped", true);
// move player up
playerVelocity.y += Mathf.Sqrt(jumpSpeed * -3f * gravityValue);
isjumping = true;
}
// Apply the movement.
playerVelocity.y += gravityValue * Time.deltaTime ;
controller.Move(playerVelocity * Time.deltaTime *2 );
// Wall jump.
// Chcek if player is not grounded and check if against the wall.
if (!isGrounded && wallchecks.iswalled && Time.time > nextFireTime)
{
if (playeraction == 1 && !isWalljumping && Time.time > wallNextFireTime)
{
// Add a next wall jump timer.
wallNextFireTime = Time.time + wallCooldownTime;
playerVelocity.y = 0;
// Draw ray to show that the wall has been push off of.
Debug.DrawRay(wallchecks.hit.point, wallchecks.hit.normal, Color.red, 1.25f);
// Apply force to character
// it fucking keeps stoping. why?
playerVelocity.y = wallJumpSpeed;
move += wallchecks.hit.normal ;
controller.Move(move * Time.deltaTime * wallJumpSpeed);
controller.Move(playerVelocity * Time.deltaTime);
Flip();
isWalljumping = true;
Debug.Log("walljump");
}
Debug.Log("touchwall");
isWalljumping = false;
}
}
public void FixedUpdate()
{
// get value of witch way the player is moving.
float movementInput = movementControl.action.ReadValue<float>();
// flipping left and right
if (movementInput < 0 && directionFacing)
{
Flip();
}
else if (movementInput > 0 && !directionFacing)
{
Flip();
}
}
void Flip()
{
// flip the character
directionFacing = !directionFacing;
character.Rotate(0, 180, 0);
}
}
Comment
Your answer
Follow this Question
Related Questions
I need HELP ! Wall Jump in 3D Platformer CharacterController 0 Answers
Preventing CharacterController sliding down edges on platforms, ground detection. 2 Answers
charController.move() much slower with exact same values? 0 Answers
Sprite sheet sprites into a material 0 Answers
Why is my character controller moving in unrelated directions? 1 Answer