Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class BackflipController : MonoBehaviour
- {
- public float backflipForce = 500f;
- public float backflipRotationForce = 100f;
- private Rigidbody rb;
- void Start()
- {
- rb = GetComponent<Rigidbody>();
- }
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Space))
- {
- PerformBackflip();
- }
- }
- void PerformBackflip()
- {
- // Apply force upwards
- rb.AddForce(Vector3.up * backflipForce);
- // Apply torque for rotation
- rb.AddTorque(transform.right * backflipRotationForce);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment