Help with Collision and Bullets

Hi i’m a newbie to Unity 3d, I’m not very familiar with some ideas, however I know enough to understand what you guys mean =D.

I’m making a multiplayer shooting game, and the idea is that you’re suppose to shoot people off the map, however the bullet that the character shoots doesn’t send the opponent in the direction of the bullet. The character names are sphereNetworkChar(Clone) when they are cloned in the Network. The script underneath this is in the bullet:

using UnityEngine;
using System.Collections;

public class bulletCollide : MonoBehaviour {

	// Use this for initialization
	void Start () {
	}
	
	// Update is called once per frame

	void Update () {
	}
	void OnCollisionEnter(Collision c)
	{
		if (c.collider.name == "sphereNetworkChar(Clone)")
		{
			Destroy(c.gameObject);
			SphereCharacterStats com = (SphereCharacterStats)c.transform.GetComponent(typeof(SphereCharacterStats));
			com.PushBack = true;
			com.CollisionVector = c.gameObject.transform.forward;
			Debug.Log("Hitted "+ c.collider);
		}
		else if (c.collider.name != "sphereNetworkChar(Clone)")
		{
			Destroy(gameObject);
		}
	}
	
}

The bullet is being pushed using AddForce() on a rigidbody, but this script is not executing properly. When the bullet collides with the character, it is suppose to grab a script in the character, and make the Pushback Variable true. When the pushback variable is true, the character is translated in the direction of the bullet. None of this works however. The script underneath is in the character:

using UnityEngine;
using System.Collections;

public class SphereCharacterStats : MonoBehaviour {
	public bool CanMove = true;
	public bool PushBack = false;
	
	public GameObject body;
	
	public int Ammo;
	public int PushbackVelocity = 0;
	
	public string LastHitBy;
	public string GunType;
	
	public Vector3 CollisionVector;
	
	// Use this for initialization
	
	void Start () {
	
	}
	
	// Update is called once per frame
	void FixedUpdate () {
		if (networkView.isMine)
		{
			if (PushBack)
			{
				Vector3 Velocity = (CollisionVector * PushbackVelocity) * Time.deltaTime;
				transform.Translate(Velocity);
				PushBack = false;
			}
	
		}
	}
	
	void OnCollisionEnter (Collision c)
	{
		if (networkView.isMine)
		{
			if (c.transform.name == "DeathBoundary")
			{
				transform.position = GameObject.FindGameObjectWithTag("Spawn").transform.position;
				//transform.rigidbody.Sleep();
			}
		}
	}
}

Any help is appreciated!

Instead of using collision, try with onTriggerEnter.
You should set all bullets colliders to isTrigger, add rigidbodies to every bullet and receptor (make sure that the option useGravity is off and isKinematic is on). That should do the trick :wink:

I’ll try that, thanks Dydra!

Pushback is only true for a single frame. It’s not going to move very far if you’re only translating for one frame.

I woudl do something like this:

        if (PushBack)
        {
            pushBackTime = Time.time; //declare pushBackTime as a private var
            Vector3 Velocity = (CollisionVector * PushbackVelocity) * Time.deltaTime;
            transform.Translate(Velocity);
            //only reset PushBack after we've moved long enough
            if(Time.time > (pushBackTime + moveTime)){ //declare moveTime as a public var
                PushBack = false;
            }

        }