I’ve done literally weeks of homework on this issue with no luck. I need to create a jump without using Unity’s rigidbody physics. I can make a jump with transform.translate well enough, but not one that looks and works well for character movement. Anyone have a solve to create a good jump mechanic without Using unity’s physics engine?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class movement : MonoBehaviour
{
[SerializeField] float throttle = 6f; // pawn speed
[SerializeField] Rigidbody rb;
[SerializeField] Vector3 pStop;
[SerializeField] Vector3 pStart;
[SerializeField] float rotspeed = 100f;
public bool isGrounded = true;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
// **** W,Q,S,E *******************************************************************
if (Input.GetAxis("Vertical") > 0 || Input.GetAxis("Vertical") < 0)
{
transform.position += transform.forward * throttle * Time.deltaTime * Input.GetAxis("Vertical");
}
if (Input.GetAxis("Horizontal") > 0 || Input.GetAxis("Horizontal") < 0)
{
transform.position += transform.right * throttle * Time.deltaTime * Input.GetAxis("Horizontal");
}
// **** END W,Q,S,E ***************************************************************
// **** A,D ***********************************************************************
float turn = rotspeed * Time.deltaTime * Input.GetAxisRaw("Turn");
transform.Rotate(0, turn, 0);
// **** END A,D *******************************************************************
// **** IF GROUNDED ***************************************************************
//reset jump
if (Physics.Raycast(transform.position, new Vector3(0, -1, 0), 1.35f))
{
isGrounded = true;
}
//make sure jump isn't possible while no ground
else
{
isGrounded = false;
}
// **** END IF GROUNDED ***********************************************************
if (Input.GetKeyDown(KeyCode.Space) && isGrounded == true)
{
//i += Time.deltaTime;
//transform.position = Vector3.Lerp(pStart, pStop, i);
//transform.position = transform.up * Time.deltaTime;
pStart = transform.position;
pStop = transform.position + new Vector3(0, 5f, 0);
float t = 0f;
while (t < 1)
{
t += Time.deltaTime;
transform.position = Vector3.Lerp(pStart, pStop, t);
}
}
}
}