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!