rigidbody Jump without addForce, or Gravity

Hey all, as title says how can I create a kinematic object that on button press jumps and returns to floor, but isn’t effected by world gravity?

Oh, and again just linking me to the docs would be ace, i just ain’t familiar with Unity without using their inbuilt physics.

Well here is something with NO physics involved whatsoever. It’s kinda shotty, but I wrote it quickly and tested it, you can tweak it to your specific needs. Just attach this to any object and pressing space will make it jump and fall back down. I made a grounded Vector3 variable so you can’t jump if you’re in mid air. Like I said kinda slow and shotty, but hopefully will give you a kickstart trying to acheive what you need to. I have written this example in C#.

``````using UnityEngine;
using System.Collections;

public class EXAMPLE : MonoBehaviour
{
float maxJumpHeight = 3.0f;
float groundHeight;
Vector3 groundPos;
float jumpSpeed = 7.0f;
float fallSpeed = 12.0f;
public bool inputJump = false;
public bool grounded = true;

void Start()
{
groundPos = transform.position;
groundHeight = transform.position.y;
maxJumpHeight = transform.position.y + maxJumpHeight;
}

void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
if(grounded)
{
groundPos = transform.position;
inputJump = true;
StartCoroutine("Jump");
}
}
if(transform.position == groundPos)
grounded = true;
else
grounded = false;
}

IEnumerator Jump()
{
while(true)
{
if(transform.position.y >= maxJumpHeight)
inputJump = false;
if(inputJump)
transform.Translate(Vector3.up * jumpSpeed * Time.smoothDeltaTime);
else if(!inputJump)
{
transform.position = Vector3.Lerp(transform.position, groundPos, fallSpeed * Time.smoothDeltaTime);
if(transform.position == groundPos)
StopAllCoroutines();
}

yield return new WaitForEndOfFrame();
}
}
}
``````