ypermat
November 17, 2020, 10:44pm
1
Hi !
I tried to knockback the player when he collide with an ennemy but i’ts not really a knockback but a teleportation backward. Here is the code :
[SerializeField]
private float force;
void OnCollisionEnter(Collision collision)
{
if (collision.transform.tag == "Player")
{
collision.transform.GetComponent<CharacterController>().Move(this.transform.forward * force);
GameController.removeLife(1);
}
}
How can I do ?
Thank you !
Do public Rigidbody rb, then do
void OnCollisionEnter(Collision collision)
{
if (collisionInfo.collider.tag == “Enemy”)
{
rb.AddForce(Vector3.back * forwardForce * Time.deltaTime, ForceMode.VelocityChange);
GameController.removeLife(1);
}
}
ypermat
November 18, 2020, 4:18pm
3
No problem, where do I need to put theses lines ?
instead of mine ? Because if I try to type only your lines like this :
public Rigidbody rb;
void OnCollisionEnter(Collision collision)
{
if (collision.transform.tag == "Player")
{
rb.AddForce(Vector3.back forwardForce Time.deltaTime, ForceMode.VelocityChange);
GameController.removeLife(1);
}
}
VS studio tells me that “forwardForce” and “Time” does not exist. He expected a “,”.
PS: The script is on my ennemies, should I make one for the player instead ?