Hello Everyone,
I am trying to make the player push another player away when you hit him.
I tried a lot of different things, just add the force from the attacker to the defender, didn't react at all.
Now the closest i got is this :
public bool hitted; //Is the player attacked?
public Vector3 attackerPos; //What is the attackers pos.
void Update (){
if(hitted == true) //if the player is attacked.
{
Debug.Log("AU"); //debug this.
rigidbody.AddForce(attackerPos,ForceMode.Acceleration); // and add the force in the opposite direction of the attacker
hitted = false;
}
}
if(canMelee)
{
body.GetComponent().SetBool("Melee", true);
canMelee = false;
Ray ray = new Ray(transform.position + Vector3.up / 4, transform.TransformDirection(Vector3.forward));
Debug.DrawRay(ray.origin, ray.direction, Color.red);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, meleeRange))
{
if(hit.collider.tag == "Player")
{
switch (character)
{
case "Brawler" :
//TODO : zorgen dat de speler het target weg pushed, over het netwerk het signaal sturen dat hij is geraakt.
hit.collider.GetComponent().hitted = true;
hit.collider.GetComponent().attackerPos = transform.position;
//Vector3 forceVec = -hit.rigidbody.velocity.normalized * 500;
//hit.collider.rigidbody.AddForce(-forceVec,ForceMode.Acceleration);
break;
case "Striker" :
//TODO : zorgen dat het target zijn camera uit en in fade.
Debug.Log("Fade Camera.");
break;
case "Bug" :
hit.collider.GetComponent().stunned = true;
stunned = false;
break;
}
canMelee = false;
}
}
}
what am i doing wrong?
It is working on the attackers screen, but on the defenders screen the player stays on the same position.
thanks in advance
↧