I dont know wtf I did xD Im ultra newbie at scripting and fk got headache with ths code
I want the character jump and cant walk on the air help plis and get grounded and not grounded, dont nderstand, Im trying my best at coding ultra newbie
void Update()
{
Move();
Jump();
}
void Jump()
{
if (Input.GetButtonDown(“Jump”))
{
rb.AddForce(Vector3.up * jumpPower);
CheckGroundStatus();
}
}
void Move()
{
float h = Input.GetAxisRaw(“Horizontal”);
float v = Input.GetAxisRaw(“Vertical”);
movement = new Vector3(h, 0f, v);
movement = Vector3.ProjectOnPlane(movement, m_GroundNormal);
// walk
if (h != 0f || v != 0f && m_IsGrounded == true) // if the player is moving at any direction
{
anim.SetFloat(“Speed”, 0.5f);
}
else
{
anim.SetFloat(“Speed”, 0);
}
if (movement != Vector3.zero)
{
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(movement.normalized), 0.2f);
//transform.Translate(movement.normalized * moveSpeed * Time.deltaTime, Space.World);
rb.velocity = movement.normalized * moveSpeed;
}
}
void CheckGroundStatus()
{
RaycastHit hitInfo;
#if UNITY_EDITOR
// helper to visualise the ground check ray in the scene view
Debug.DrawLine(transform.position + (Vector3.up * 0.1f), transform.position + (Vector3.up * 0.1f) + (Vector3.down * m_GroundCheckDistance));
#endif
// 0.1f is a small offset to start the ray from inside the character
// it is also good to note that the transform position in the sample assets is at the base of the character
if (Physics.Raycast(transform.position + (Vector3.up * 0.1f), Vector3.down, out hitInfo, m_GroundCheckDistance))
{
m_GroundNormal = hitInfo.normal;
m_IsGrounded = true;
anim.applyRootMotion = true;
}
else
{
m_IsGrounded = false;
m_GroundNormal = Vector3.up;
anim.applyRootMotion = false;
}
}