Game Development Asked by Aimon Z. on December 25, 2020
I found an example with which the CharacterController can jump, but it does not work to remake it so that it jumps to a certain point/distance, and the jumpHeight itself was calculated for speed and gravity, I found this article on Wikipedia, but I don’t even know why to begin.
public class ExampleClass : MonoBehaviour
{
public float speed = 6f;
public float jumpHeight = 8f;
public float gravity = 20f;
private Vector3 moveDirection = Vector3.zero;
CharacterController controller;
void Start()
{
controller = GetComponent<CharacterController>();
}
void Update()
{
if (controller.isGrounded)
{
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
// Method for jump, calling from other script.
void Jump(float pointX)
{
}
}
I can’t find examples for the Character Controller, although I did find one for the Rigidbody.
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP