Question by
Robiiii · Jul 04, 2019 at 07:28 PM ·
physicsrigidbodylocomotion
Rigidbody.isKinematic teleporting to ground after toggle
So I wanted to add a Jetpack to the Unity default FP Character. By pressing c you deactivate the "isKinematic" option of the FP Character and apply a Force, when releasing c "isKinematic" is activated again. However, after releasing the button, the Player gets teleported back to the surface. Got any tips? This is the Jackpack.cs script:
public class Jetpack : MonoBehaviour
{
private Rigidbody rb;
[SerializeField]
private InventoryScript Invent;
[SerializeField]
float JetpackBoost;
// Start is called before the first frame update
void Start()
{
rb = GameObject.FindGameObjectWithTag("Player").GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate()
{
if (!Input.GetKey(KeyCode.C))
rb.isKinematic = true;
if (Input.GetKey(KeyCode.C))
rb.isKinematic = false;
if (Input.GetKey(KeyCode.C))
{
rb.AddForce(Vector3.up * JetpackBoost);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Move rigidbody cube without it tumbling 2 Answers
Virtual accelerometer/gyro 0 Answers
AddForce in Coroutine 1 Answer
Issues With Using Rigidbodies and Hinge Joints in a Tube 0 Answers