- Home /
Gun going through floor when dropping?
hi, i made a gun system but when i drop a gun it falls through the terrain. anything i need to explain further ill be around, heres my code, however im not sure it has to do with my code. ill also leave my project for people to have a peek.
using UnityEngine;
using System.Collections;
public class Gun : MonoBehaviour {
public GameObject Weapon1Get;
public GameObject Weapon2Get;
private GameObject WeaponDropped;
void OnMouseDown () {
Debug.Log ("YES");
WeaponDropped = Weapon1Get.GetComponent <Weapon1> ().CurrentWeapon;
WeaponDropped.collider.enabled = true;
WeaponDropped.rigidbody.detectCollisions = true;
collider.enabled = false;
rigidbody.detectCollisions = false;
Weapon1Get.GetComponent <Weapon1> ().CurrentWeapon = gameObject;
}
void OnCollisionEnter (Collision Col)
{
if (Col.gameObject.tag == "Player")
{
Physics.IgnoreCollision (collider, Col.gameObject.collider);
}
}
}
https://drive.google.com/file/d/0B2ZiQtohl3tmdXpXVmRNNmxSTTQ/view?usp=sharing
Also as you can see at the bottom of the code, i thought maybe the players collision with the gun was the problem but its not.
Answer by ddulshan · Feb 14, 2015 at 01:48 PM
Try Weapon1Get.collider.enabled = true
and Weapon1Get.rigidbody.detectCollisions = true;
Instead what you've already written.
i tried that. the reason i did this ins$$anonymous$$d is because it didnt work. @DragonWarrior_Dnw_
and now i have a code that just makes it ignore collision with player when its the gun.
my new code, after modifying it:
using UnityEngine;
using System.Collections;
public class Gun : $$anonymous$$onoBehaviour {
public GameObject Weapon1Get;
public GameObject Weapon2Get;
public GameObject PlayerGet;
public bool IsStarterGun;
void Start () {
if (IsStarterGun == true)
{
Physics.IgnoreCollision (collider, PlayerGet.collider, true);
}
}
void On$$anonymous$$ouseDown () {
Physics.IgnoreCollision (collider, PlayerGet.collider, true);
Weapon1Get.GetComponent <Weapon1> ().CurrentWeapon = gameObject;
}
void OnCollisionEnter (Collision Col) {
if (Col.gameObject.tag == "Surface" && Weapon1Get.GetComponent <Weapon1> ().CurrentWeapon != gameObject)
{
Physics.IgnoreCollision (collider, PlayerGet.collider, false);
}
}
}
Your answer
Follow this Question
Related Questions
Allow picked up object to collide with game level GameObjects 1 Answer
Gun Manager only working once 1 Answer
Object falls through floor 1 Answer
Enemy falls through floor when both have collider 2 Answers
Fps Gun Scrpt :) 1 Answer