#I did not edit it. Can you confirm the
1 messages · Page 1 of 1 (latest)
Yeah, debugging via logs. The Jump gets triggered, I'm grounded..
trying to share the code..
private void Update()
{
Movement();
}
private void Movement()
{
m_moveVelocity.x = m_inputMovement.x * m_moveSpeed * Time.deltaTime;
m_moveVelocity.z = m_inputMovement.y * m_moveSpeed * Time.deltaTime;
m_moveVelocity.y = -m_gravity * Time.deltaTime; // Apply gravity.
var moveVelocityInWorldSpace = transform.TransformDirection(m_moveVelocity);
m_characterController.Move(moveVelocityInWorldSpace);
}
private void Jump()
{
if (m_characterController.isGrounded)
{
m_moveVelocity.y += Mathf.Sqrt(m_jumpForce * 2 * -m_gravity);;
}
}
It doesnt look like you're running the Jump() function
Can I see that code?
m_inputControls.Character.Jump.performed += e => Jump(); (in Awake)
using System;
using UnityEngine;
public class PlayerMovement2 : MonoBehaviour
{
[SerializeField, NotNull]
private CharacterController m_characterController = null;
[SerializeField, Tooltip("Move speed each frame in meters.")]
private float m_moveSpeed = 5f;
[SerializeField]
private float m_gravity = 20;
[SerializeField]
private float m_jumpForce = 30;
private Vector2 m_inputMovement;
private Vector3 m_mouseInput; // TODO: temp
public Vector2 MouseInput => m_mouseInput; // TODO: temp
private InputControls m_inputControls;
private Vector3 m_moveVelocity = Vector3.zero;
private float m_jumpVelocity;
private void Awake()
{
m_inputControls = new InputControls();
m_inputControls.Enable();
m_inputControls.Character.Movement.performed += e => m_inputMovement = e.ReadValue<Vector2>(); // Normalized
m_inputControls.Character.View.performed += e => m_mouseInput = e.ReadValue<Vector2>(); // delta
m_inputControls.Character.Jump.performed += e => Jump();
}
private void Update()
{
Movement();
}
private void Movement()
{
m_moveVelocity.x = m_inputMovement.x * m_moveSpeed * Time.deltaTime;
m_moveVelocity.z = m_inputMovement.y * m_moveSpeed * Time.deltaTime;
m_moveVelocity.y = -m_gravity * Time.deltaTime; // Apply gravity.
var moveVelocityInWorldSpace = transform.TransformDirection(m_moveVelocity);
m_characterController.Move(moveVelocityInWorldSpace);
}
private void Jump()
{
if (m_characterController.isGrounded)
{
m_moveVelocity.y += Mathf.Sqrt(m_jumpForce * 2 * -m_gravity);;
}
}
}
this is the whole class
Try to replace m_moveVelocity.y += with m_moveVelocity.y =
Try to change m_gravity to a negative number like -10
tried, not working
I fly upwards when changed..
because I apply gravity each frame in Movement() method
Lower the jump height to like 2
I tried numbers from -20k to 20k ..
I believe I use numbers like 2-3 jump height and -5 to -10 gravity
sure, me too, I was just curious
You should only be applying the gravity when the player is not grounded
Basically the m_moveVelocity.y += Mathf.Sqrt(m_jumpForce * 2 * -m_gravity);; does nothing
ok
Remove the extra semi-colon on that line
I need to go and I've been on my phone so I haven't been able to really read your code, sorry. Hopefully you get it working soon though
don't worry about the semicolon, does nothing, typo.. no probs