- Home /
fliiping when using the rigidbody.addforce function
i an trying to add a dash into my game however when i call the rb.AddForce(transform.forward * dashstrength); line of code by pressing shift as my code lokks like this /////////// using System.Collections; using System.Collections.Generic; using UnityEngine;
public class jumping : MonoBehaviour { public Rigidbody rb; public bool groundcheck = true; public float dashstrength = 20;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && groundcheck == true)
{
rb.AddForce(new Vector3(0, 5, 0), ForceMode.Impulse);
groundcheck = false;
}
if (Input.GetKeyDown(KeyCode.LeftShift))
{
rb.AddForce(transform.forward * dashstrength);
}
}
private void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.name == "Ground")
{
groundcheck = true;
}
}
} /////////////////// my character flips by increasing the depth of my box colider it reduced the impact however not get rid of it does any one have a solution my box colider as shown in the flipping when using addforce function image linked below
[1]: /storage/temp/179760-flipping-when-using-addforce-function-problem.png
Answer by wishinggem · Jun 04, 2021 at 02:06 PM
dont worry i have fixed it with rb.constraints = RigidbodyConstraints.FreezeRotation;
Your answer
Follow this Question
Related Questions
Simple rigidbody.AddForce only applying once each time key is pressed 1 Answer
Stop movement of rigid bodies 2D after collision 1 Answer
How to make RigidBody's movement using fixed movement/velocity and other forces all together? 3 Answers
Addforce for shotgun raycasts 0 Answers
Character flies away at high speed with Rigidbody.AddForce 1 Answer