- Home /
I've made an almighty push like power but it doesnt affect anything.
I have made a script that adds force when it touches an object with the tag ForwardForceCollider and I have it tagged with the tag, but when i touch the collider nothing happens.
public class ForceCilinder : MonoBehaviour { public float pushForce = 10; void OnTriggerEnter(Collider pushedObject) {
if (pushedObject.gameObject.tag == ("ForwardForceCollider"))
{
Rigidbody pushedBody = pushedObject.GetComponent<Rigidbody>();
pushedBody.AddForce(transform.forward * pushForce, ForceMode.Impulse);
}
}
void Update()
{
}
}
Answer by AbandonedCrypt · Feb 02, 2021 at 08:46 AM
Use Debug.Log() to check if it even gets inside the tag comparison clause. Remove the braces around your string. Use CompareTag(). Check if your pushedObject has that exact tag. Use code tag correctly for readability.
Also ideally do your physics in FixedUpdate().
Your answer
Follow this Question
Related Questions
Enemy object model not facing the player correctly 1 Answer
Script sets same value to other script in all objects instead of just one. 1 Answer
Everything working fine in Editor but in device the find object with tag throwing null exception 2 Answers
how to disable player inputs? 1 Answer
Problem with the camera, 2D. 0 Answers