I have a script that is meant to have the players, rigidbodies, rotation always locked, and when you click, but only while clicking, the position is frozen, but when I freeze the position it unfreezes rotation, is there a way to solve this?
void Start()
{
rb.constraints = RigidbodyConstraints.FreezeRotation;
time = starttime;
dash = false;
}
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
fist1.velocity = (Vector3.forward * speed * punch);
rb.constraints = RigidbodyConstraints.FreezePosition;
}
}
Rigidbody contraints are flags
void Start()
{
rb.constraints = RigidbodyConstraints.FreezeRotation;
time = starttime;
dash = false;
}
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
fist1.velocity = (Vector3.forward * speed * punch);
rb.constraints |= RigidbodyConstraints.FreezePosition; // Freeze position & rotation
}
else if (Input.GetButtonUp("Fire1"))
{
rb.constraints &= ~RigidbodyConstraints.FreezePosition; // Unfreeze position
}
}
Another solution:
void Start()
{
rb.constraints = RigidbodyConstraints.FreezeRotation;
time = starttime;
dash = false;
}
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
fist1.velocity = (Vector3.forward * speed * punch);
rb.constraints = RigidbodyConstraints.FreezeAll;
}
else if (Input.GetButtonUp("Fire1"))
{
rb.constraints = RigidbodyConstraints.FreezeRotation;
}
}