Questions in topic: "oncollisionenter"http://answers.unity3d.com/questions/topics/single/1477.html
The latest questions for the topic "oncollisionenter"GameObject disappears for a short time after collisionhttp://answers.unity3d.com/questions/1283197/gameobject-disappears-for-a-short-time-after-colli.html
According to my script the car should be launched into the air and when it lands back on the ground it should resume its original track of the navmesh. **Sometimes** when another gameobject collides with this gameobject(car) the car disappears for a second and then appears again and follows its orignal track of the navmesh. (i believe everything works addforce etc. but it just disappears at the moment when addforce should be working)
It is also worth noting this only happens on devices with a high fps like a pc or high-end android devices. On my phone (lower fps) everything works perfectly.
Rigidbody rb;
NavMeshAgent agent;
void OnCollisionEnter (Collision other)
{
if(other.gameObject.CompareTag("Wrecking Ball") && time >= 1.0f)
{
time = 0;
InvokeRepeating ("Timer", 1.0f, 0.5f);
//pause navmesh oncollision
agent.updatePosition = false;
agent.Stop ();
//effect of collision
health = health - damage;
rb.AddForce (new Vector3 (0, 15, 0), ForceMode.Impulse);
transform.Rotate (35, 0, 0);
//resume after 2 seconds
InvokeRepeating("Resume",2.5f,0.1f);
}
void Resume()
{
//resume original track of car
if (gameObject.transform.position.y <= 0.501 && health != 0)
{
agent.Warp (transform.position);
//if using infinite scene another script is called for setting the correct track of the car
if (SceneManager.GetActiveScene().name == "Infinite")
{
InfiniteAgent infiniteAgent = gameObject.GetComponent<InfiniteAgent> ();
infiniteAgent.destPoint -= 1;
}
else
{
AgentScript agentScript = gameObject.GetComponent<AgentScript> ();
agentScript.destPoint -= 1;
}
agent.Resume ();
agent.updatePosition = true;
CancelInvoke ();
}
}
void Timer()
{
//so the wrecking ball isn't destroying the car right away
time += 1;
}androidaddforcenavmeshagentoncollisionenteragentFri, 09 Dec 2016 21:50:31 GMTAminSB00Collision Detection Not Working (JS)http://answers.unity3d.com/questions/1282183/collision-detection-not-working-js.html
I copied everything off of the unity guide and it just never activates.
#pragma strict
function Start () {
}
function Update () {
}
function onCollisionEnter(col:Collision){
print("Collision Detected");
}oncollisionenterWed, 07 Dec 2016 22:43:06 GMTXLSgamerPowerup issue - Speedhttp://answers.unity3d.com/questions/1280940/powerup-issue-speed.html
Hi All,
I am currently making a speed powerup for a game, which I'm mainly struggling with resetting the value back to its original. It is mainly due to the fact that I need to access the speed variable from another script, as i want to say: On collision of this object -> increase speed -> wait for 5 seconds -> speed is set back to original. Some help would be great! Thankyou.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpeedPowerup : MonoBehaviour {
public float fasterSpeed;
public bool isFaster = false;
public float f = 100;
public void OnTriggerEnter(Collider other) {
if (other.tag == "Player") {
isFaster = true;
Debug.Log ("Speed Powerup");
PlayerMovement theSpeed = other.gameObject.GetComponent<PlayerMovement> ();
theSpeed.speed = fasterSpeed;
StartCoroutine (WaitTime ());
}
}
public IEnumerator WaitTime() {
yield return new WaitForSeconds (5);
isFaster = false;
}
}c#coroutinegetcomponentoncollisionenterienumeratorMon, 05 Dec 2016 18:09:43 GMTbradarnottCS1525 Unexpected symbol '=', HELP!!!http://answers.unity3d.com/questions/1278134/cs1525-unexpected-symbol-help.html
With this code,
using UnityEngine;
using System.Collections;
public class PainSound : MonoBehaviour {
public AudioClip whenHurt;
private AudioSource source;
void Awake () {
source = GetComponent<AudioSource>();
}
void Update () {
}
void OnCollisionEnter (Collision coll)
{
if (coll.relativeVelocity.magnitude > 30f && other.tag = "projectile" || other.tag = "car")
source.PlayOneShot(whenHurt,1F);
}
}
I get CS1525, Unexpected symbol '='. Why?
**I need help urgently, project is due soon!**collisiononcollisionenterif statementcs1525||Tue, 29 Nov 2016 19:33:33 GMTNova-1504How to make gameObject make only one collisionhttp://answers.unity3d.com/questions/1277035/how-to-make-make-gameobject-make-only-one-collisio.html
Hi I have question for which I haven't been able to find an answer thus far. I have two game objects next to each other and each one has a collider. Now when a third object collides with one of the game objects then the direction of that third object takes a different direction based on which gameObject/collider it touched. This works fine for most part when the gameObjects are hit cleanly but when it collides in the middle of both colliders then it takes a direction in the middle, this causes a problem for my game.
I wanted to know how to make sure that only one collider/collision is triggered (doesn't matter which one) when any other objects collides in the middle of both gameObjects.c#collisioncolliderontriggerenteroncollisionenterMon, 28 Nov 2016 08:04:32 GMTmayanayaColliding multiple enemys but only one at a time attackedhttp://answers.unity3d.com/questions/1277087/colliding-multiple-enemys-but-only-one-at-a-time-a.html
Hello,
I've got a litte game where the player is able to control a group of soldiers, each soldier is individual. There are enemy soldiers on the battlefield which could been attacked by moving the group of soldiers to the position of the enemy.
Each soldier should attack only one enemy approx. every 1 sec. And there is the thing i struggle with.
**Question:**How do I get the soldiers to attack only one enemy at a time and not every soldier they are colliding with?
void OnCollisionStay2D(Collision2D coll)
{
if ((coll.gameObject.tag == "Enemy" && this.tag == "Friend") || (coll.gameObject.tag == "Friend" && this.tag == "Enemy")) //The if, because friendly and enemy soldiers are controlled by same script
{
HitTimer += Time.deltaTime;
if (HitTimer > HitTime)
{
coll.gameObject.GetComponent<SoldierLogic>().Health -= 30;
HitTimer = 0f;
}
}
}
Im thankful for every hint!
Best regardsc#collisioncollideroncollisionenterattackSun, 27 Nov 2016 18:07:53 GMTJanNatterEnd Game (Stop spawning) with OnTriggerEnter or OnCollisionEnter?http://answers.unity3d.com/questions/1276820/end-game-stop-spawning-with-ontriggerenter-or-onco.html
Hello! I am working on a color matching catch game where you need to match the color of the game object on the bottom with the color of the game object falling from the top of the screen. And what I am trying to achieve is as soon as you match the colors incorrectly, it's game over and objects from the top need to stop spawning.
I'm not sure if I need to create a new script for this or just add code into a current script I already have. I've got a game controller script that handles the scrolling of the "catch" objects at the bottom of the screen, as well as a spawning script, and a score script where I'm already calling an OnTriggerEnter2D to update my score. what would I need to code in a new "Game Over" script or add on to a current one to achieve this goal? Any advice or pointing me in the right direction is greatly appreciated, thank you!unity 5scripting problemontriggerenteroncollisionenterspawningSun, 27 Nov 2016 01:53:55 GMTDKitch9Compare Tag on Collision (Collider.CompareTag)http://answers.unity3d.com/questions/1272543/compare-tag-on-collision-collidercomparetag.html
Hi all,
First time poster, forums have been a great help to me.
I have encountered this issue, and after trying a few combinations I need to ask for help!
I want to compare tag with the object I'm colliding with, I have the below code, but it seems to just ignore all collisions, let alone whatever I want it to collide with, my debug log also does not come up in console.
If you're wondering why I play with gravity, i have a floating companion that I use as a grenade.
If i remove the If statement everything works as intended, but it will obviously instantiate my explosion on every contact.
TLDR: want instantiation to happen only with collision with Enemy tags.
void OnCollisionEnter(Collider col) {
if (col.CompareTag("Enemy"))
{
Instantiate (explode, location.position, transform.rotation);
Debug.Log ("awake");
}
rbody.useGravity = false;
}instantiatecollidertagoncollisionentercomparetagThu, 17 Nov 2016 07:18:27 GMTh0nestjimMake object child on collision Make object child off collisionhttp://answers.unity3d.com/questions/1270012/make-object-child-on-collision-make-object-child-o.html
http://answers.unity3d.com/questions/25417/making-an-object-a-child-on-collision.html
i tried this answer and could not get it to work. it was doing compile errors non stop.
using UnityEngine;
using System.Collections;
public class Collision : MonoBehaviour {
void Update () {
}
void OnCollisionEnter(other collision) {
if(other.gameObject.tag == "player") {
other.transform.parent = transform;
}
}
}
^ this is what i have so far for the collision enter.
I went with void because :
function OnTriggerEnter (other : Collider) {
if(other.gameObject.tag == "objectYouWant") {
other.transform.parent = transform;
}
}
this was not working as function would not register i would get compile error after error and spent 4 hours trying to fix it.
what i want to do is i have a (Object) that is rotating. (Planet) when my spaceship goes and lands on it with a gravity script, it needs to be a child of the ROTATING (Object) PLANET. So it can rest on its landing spot, and rotate along with the planet without being left in space.
When the thrusters go off and its not colliding with the (Object) null the child so it can go to another planet.
I cant get it to work the first link wasnt complete script and im sure theres errors im missing.
Can someone help please.
function OnCollisionExit (other : Collision) { this is expecting an identifier but i cannot for the life of me find out where it goes
using UnityEngine;
using System.Collections;
public class Collision : MonoBehaviour {
void Update () {
}
function OnCollisionEnter (other : Collision) {
if(other.gameObject.tag == "objectYouWant") {
other.transform.parent = transform;
}
}
function OnCollisionExit (other : Collision) {
if(other.gameObject.tag == "objectYouWant") {
other.transform.parent = null;
}
}
}
i saw that im mixing two different languages together
so i tried to fix that with
using UnityEngine;
using System.Collections;
public class Collision : MonoBehaviour {
void Update () {
}
void OnTriggerEnter(Collider other)
{
if (other.GetType() = "Player") {
other.transform.parent = transform;
}
}
void OnTriggerExit(Collider other) {
if (other.GetType() = "Player") {
other.transform.parent = null;
}
}
}
tried to do js
#pragma strict
function Start () {
}
function Update () {
function OnCollisionEnter (orange : Collision) {
if(orange.gameObject.tag == "Player") {
orange.transform.parent = transform;
}
}
function OnCollisionExit (orange : Collision) {
if(orange.gameObject.tag == "Player") {
orange.transform.parent = null;
}
}
}
Now i get unexpected token. Whats the solution anyone ?oncollisionenteroncollisionexitFri, 11 Nov 2016 10:47:42 GMTDeadWabbitOnCollisionEnter not being called despite objects colliding and movinghttp://answers.unity3d.com/questions/1268518/oncollisionenter-not-being-called-despite-objects.html
Still working on a 2D space shooter, and I can't seem to register any OnCollisionEnters. The bullet is able to push enemies and bounce off walls, "is kinematic" is on only for walls, and all 3 elements have box/circle colliders and Rigidbody 2Ds (box for walls and circle for bullets and enemies).
Right now I've got
void OnCollisionEnter(Collision collision)
{
Debug.Log("Bullet Collides");
Destroy(gameObject);
}
The Debug message doesn't appear and the bullet prefab the script is attached to isn't being destroyed.collideroncollisionentercollisiondetectioniskinematicTue, 08 Nov 2016 07:36:27 GMTAdamtheNoobTwo objects with Rigidbodies and Colliders, yet collision script not working!http://answers.unity3d.com/questions/1262713/two-objects-with-rigidbodies-and-colliders-yet-col.html
I have a sphere and a cube. Both have rigidbodies and colliders, yet the collision script is not working. I've also played around with the kinematic/gravity boxes but to no avail.
*Debug.Log* is still not displaying in the console window...
Kindly see screenshots below and check what's wrong with the object's properties in the inspector.
I'm not really sure what's wrong with the object's properties or with the code
Sphere and Cube Properties
![alt text][1]
Script
![alt text][2]
Kindly tell me if you see or don't see any errors in my file.
[1]: /storage/temp/80966-1and2.jpg
[2]: /storage/temp/80967-3.jpgoncollisionenterWed, 26 Oct 2016 12:23:46 GMTryekisOnTriggerEnter happens too latehttp://answers.unity3d.com/questions/1261584/ontriggerenter-happens-too-late.html
Hey folks,
I'm firing a bomb into a chosen direction.
The Bomb has a script on it which includes the OnTriggerEnter() function.
So when the bomb enters a collider it happens 2 out of 3 times that the bomb passes the object and explodes within or at the back of the object instead on impact.
I tried increasing the radius of the bomb's collider but it didn't fix the problem.
And yes, the collider has IsTrigger checked.
The Unity documentation says "The Colliders involved are not guaranteed to be at the point of initial contact."
So its better to use OnCollisionEnter() in this case?
Thank you in advance.ontriggerenteroncollisionenterMon, 24 Oct 2016 12:03:28 GMTDominikHeynObject won't collide with FPS Controllerhttp://answers.unity3d.com/questions/1257439/object-wont-collide-with-fps-controller.html
Hi everyone, I'm still super new to Unity, so sorry if this question sounds dumb or anything, but I've been experiencing a lot of trouble with the problem that an object won't detect collisions with the FPS Controller.
Here's the object's code:
using UnityEngine;
using System.Collections;
public class BulletOnGround : MonoBehaviour {
void OnCollisionEnter(Collision collision){
Debug.Log ("Collision Detected");
if (collision.gameObject.name==("FPSController")){
Debug.Log ("Collided With Player!");
Destroy (gameObject);
}
}
}
Any help at all would be appreciated, thank you!collisioncharactercontrolleroncollisionenterMon, 17 Oct 2016 05:00:31 GMTGaming_DragonOnCollisionEnter2D doesn't display debug messagehttp://answers.unity3d.com/questions/1255311/oncollisionenter2d-doesnt-display-debug-message.html
I have two characters who currently collide. The thing is, when they collide, the debug message doesn't show up. They both have rigidbody2D and box colliders 2D. Is trigger and is kinematic is turned off. gravity scale is set to 0.
void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.tag == "wallX")
{
Debug.Log("HIT!");
//this.transform.rotation = Quaternion.LookRotation(moveDirection);
}
else if (other.gameObject.name == "background")
{
Debug.Log("HIT!");
//this.transform.rotation = Quaternion.LookRotation(moveDirection);
}
}
Please help me.oncollisionentercollision2dWed, 12 Oct 2016 12:19:28 GMTVitashiqueCan not get OnTriggerEnter and OnCollisionEnter to work!?http://answers.unity3d.com/questions/1248570/can-not-get-ontriggerenter-and-oncollisionenter-to.html
I have two objects with colliders and one with a rigid body. Here are their inspector settings.
This first is the cube, which has the rigid body and is moving during the collision.
![alt text][1]
Second here is the plane that the cube is colliding with
![alt text][2]
I am using a simple script just to print a debug if there is any collision. This script is inside the cube object.
void onCollisionEnter(Collision collision){
Debug.Log (collision.gameObject.name);
}
I have searched through the documentation for hours, and I appear to be doing everything correct, but there is no collision.
Any help is appreciated. Thanks so much.
[1]: /storage/temp/78976-cube.png
[2]: /storage/temp/78978-ground.pngontriggerenteroncollisionentertriggerscollisionsMon, 26 Sep 2016 17:00:49 GMTPayton-DugasProblem with gravity, OnCollisionEnter and OnCollisionExithttp://answers.unity3d.com/questions/1241424/hi-everyone-i-need-help-with-following-problem.html
Description: I want my gameObject to rotate by 90 degrees when it collides with wall. After that i want to turn off gravity so it can go upwards. When it gets off the wall i want to reset rotation and turn gravaty back on. Problem: When I use OnCollisionEnter it works (rotates gameObject and turns off gravity) but when I add OnCollisionExit (to reset rotation and turn gravity on when there is no more wall) gravity dosen't turn off in OnCollisionEnter function it stays On always. Note that OnCollisionEnter works when OnCollisionExit isn't added in script.
Here is my code
void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "Colli")
{
Vector3 rotatY = new Vector3(-90, 0, 0);
transform.Rotate(rotatY);
rb.useGravity = false;
}
}
void OnCollisionExit(Collision other)
{
Vector3 resetRot = new Vector3(0, 0, 0);
transform.Rotate(resetRot);
rb.useGravity = true;
}rotationrigidbodygravityoncollisionenteroncollisionexitFri, 09 Sep 2016 17:48:32 GMTThevalecollisions not detectedhttp://answers.unity3d.com/questions/1241207/collisions-not-detected.html
I am trying to make a game where a ball collides with a wall which loads another scene through onCollisionEnter. The project works fine in the Unity but nothing happens when I collide with the wall in the android version. I've tried using onTriggerEnter. Is there any way to fix this problem or is there any way to get around the problem and collide with the door with other code?androidcollisioncollidersoncollisionenterFri, 09 Sep 2016 07:54:18 GMThgcodeJump on the groundhttp://answers.unity3d.com/questions/1236573/jump-on-the-ground.html
Hello! I know that a lot of these questions have already been asked, but I have looked through many, and none of them seem to work for me. My problem is: I want my player to jump only when he is on the ground.
I'm new with scripting, i'm really a beginner. The original code is from the unity tutorial "roll-a-ball".
Sorry for my bad english, and here is my code, any help is appreciated!
using UnityEngine;
using System.Collections;
public class Movimento : MonoBehaviour {
public float speed;
public float jump;
private Rigidbody rb;
void Start ()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, 0.0f);
if (Input.GetKeyDown(KeyCode.Space)) {
GetComponent<Rigidbody>().AddForce(new Vector3(0, jump, 0)); }
rb.AddForce (movement * speed);
}
}c#collisiongameobject3doncollisionenterTue, 30 Aug 2016 03:13:33 GMTRefoxyUNET OnCollisionEnter issueshttp://answers.unity3d.com/questions/1236542/unet-oncollisionenter-issues.html
Hello again!
I'm having some issues with OnCollisionEnter as my code only works on the remote clients once in a while, and I really don't know why.
void OnCollisionEnter(Collision col)
{
CheckHit(col.gameObject);
}
[Client]
void CheckHit(GameObject col)
{
if (col.GetComponent<Collider>().CompareTag("Ball"))
{
if (col.gameObject.GetComponent<BallOwner>().lastTouchedBy == TeamSetup.Team.Unassigned)
{
return;
}
//If the ball is has been touched by another team than ourselves, then we are hit
if (col.gameObject.GetComponent<BallOwner>().lastTouchedBy != gameObject.GetComponent<TeamSetup>().currentTeam)
{
OnHit();
CmddebugMessage("On hit is called");
//Reset the ball again, so that we don't get hit by a dead ball
RpcResetBall(col.gameObject);
}
}
}
**Note** the code always works when called from the server, as being the server throws the ball at a remote client.networkingmultiplayeroncollisionenterserversideTue, 30 Aug 2016 00:29:02 GMTNFMynsterOnCollisionEnter cant work with wheel collidershttp://answers.unity3d.com/questions/1233658/oncollisionenter-cant-work-with-wheel-colliders.html
Hi. I have a car with 4 wheel colliders(+rigidbody).When they collide with the ground,OnCollisionEnter is not activated but if the car body collides with the ground it is ok.!!! My script is both ground object and root car object(rigidbody object)unity 5rigidbodyoncollisionenterwheelcolliderTue, 23 Aug 2016 16:48:43 GMTmahdiiiAdd a score whenever a riceball hits the floating platformhttp://answers.unity3d.com/questions/1229298/add-a-score-whenever-a-riceball-hits-the-floating.html
My riceball is bouncing and the player should catch the riceball in a small platform. When the player haven't catch the riceball, it's game over. I want the score to increment by one whenever the riceball make contact with the small platform. How do I do this?<br>
I added a script in the player sprite. The player sprite is the small platform. The score stays in zero but i want the score to increment whenever it collides with the riceball.
using UnityEngine;
public class ScorePlayer : MonoBehaviour {
private Transform tr2d;
public static int playerScore = 0;
// Use this for initialization
void Start()
{
tr2d = GetComponent<Transform>();
}
// Update is called once per frame
void OnTriggerEnter2D(Collider2D hitInfo)
{
if (hitInfo.name == "riceball")
{
playerScore += 1;
}
}
public void OnGUI()
{
GUI.Label(new Rect(Screen.width / 2 + 150, 20, 100, 100), "" + playerScore);
}
}collisionontriggerenterstaticoncollisionentercounterMon, 15 Aug 2016 15:43:57 GMTmarisannnDisabling Script on many Objects one at a time.http://answers.unity3d.com/questions/1229232/disabling-script-on-many-objects-one-at-a-time.html
In my project i have many platforms and they all share same script.
What i'm trying to achieve is that when player collides with the platform the script that is attached to the platform will deactivate. But only that one script on that specific platform the player is standing on. All the other scripts, on other platforms he is not standing on, should be activated until player collides with them.
Thank you guys for any answers or ideas on how to solve this problem.
So far i have:
public GameObject[] cubes;
public Script theScript;
Start ()
{
cubes = GameObject.FindGameObjectsWithTag("cubes");
theScript = ?
}
void OnCollisionEnter2D(Collision2D other)
{
if(other.gameObject.tag == "cubes")
{
theScript.enabled = false
}
}scripting problemobjectsoncollisionenterdisable2d platformerSun, 14 Aug 2016 07:26:42 GMTRicharrd82How to succesfully implement OnCollisionEnter?http://answers.unity3d.com/questions/1227530/how-to-succesfully-implement-oncollisionenter.html
I'm pretty sure I'm missing something very simple but, alas, my line of sight is blurrying my vision here.
Please help me.
In order to show my problem in a simple scenario, I created a new scene.
Added a simple 3D Cube, clone it and move it near the original.
Inspector cube a:
http://cdn1.npaste.com/image/original/1470805079/obogfk.jpg
Inspector cube b:
http://cdn1.npaste.com/image/original/1470805127/oboghe.jpg
Attached a simple C# behavior component to Cube b:
http://cdn1.npaste.com/image/original/1470805171/obogix.jpg
Press play and move the cubes so they can kisskiss:
http://cdn1.npaste.com/image/original/1470805236/obogk4.jpg
Nothing... Needless to say, I feel very hmm... limited (not to say super stupid) in how to implement a simple collision detection.
I came across with this problem at attaching a similar script to a fired rocket towards some asteroids.
Any ideas of what am I missing here? Thanks in advance.c#collision detectiononcollisionenterbasicsWed, 10 Aug 2016 05:15:01 GMTmireles001OnEnterTrigger wont workhttp://answers.unity3d.com/questions/1224867/onentertrigger-wont-work.html
I have a moving game object with rigidbody and box collider. I have set up another box collider in the way of its path and want to make the moving object rotate 90 degrees when it goes through the box collider.
despite many attempts nothing works I have also tried using OnCollisionEnter . this is my code.
using UnityEngine;
using System.Collections;
public class tilts : MonoBehaviour {
void OnTriggerEnter (Collider collision)
{
if(collision.gameObject.tag == "boxc")
{
transform.Rotate (0, 0, 90);
}
}
}triggerontriggerenteroncollisionenterboxcolliderWed, 03 Aug 2016 21:26:18 GMTCrashmarcozChecking if Player object is out of boundshttp://answers.unity3d.com/questions/1224732/checking-if-player-object-is-out-of-bounds.html
Hello,
I have written a javascript code for checking the player if they have fell out of bounds. This is a 3D platformer that I am tring to make.
I am recieving errors and can not run the game with this script. What am I doing wrong in the code? Please help!
![alt text][1]
[1]: /storage/temp/75409-check-player-is-out-of-bounds.jpgcollisiononcollisionentercompilergameobject.taggameobject.nameWed, 03 Aug 2016 15:22:59 GMTMschriWeird Collision Detection with a Cube and OnCollisionEnterhttp://answers.unity3d.com/questions/1224054/weird-collision-detection-with-a-cube-and-oncollis.html
In my project, I use OnCollisionEnter to detect when a cube hits another cube. For some reason, the cubes detect each other without actually colliding. My program has the cubes fall when they collide and each time they start to fall, they are a small distance away from each other.
Careful testing reveals that the area in which the collisions are detected are in what seems to be a sphere with diameter sqrt 3 (cubes have side length 1). Is there any way to fix this or figure out why it is happening?
Edit (Additional Info and Code):
I checked and my cube definitely has a box collider and no other colliders. It is also not the child of an object. It has spheres with no rigidbodies and colliders set to triggers as children but deleting them had no visual effect on the problem.
Here is the OnCollisionEnter which sets a variable that is used in another script.
Note: There is some code related to SteamVR since I am building this game as a virtual reality experience.
void OnCollisionEnter(Collision other)
{
if (other.collider.gameObject.CompareTag("Connecter") == false)
{
if (other.collider.gameObject.name != "Ground")
{
if (other.collider.gameObject.GetComponent<Held>().isCarried() == true && this.isCarried() == true)
{
//yetAnotherBool = true;
otherP = other;
var deviceL = SteamVR_Controller.Input(indexL);
var deviceR = SteamVR_Controller.Input(indexR);
var rb = this.gameObject.GetComponent<Rigidbody>();
var otherRB = other.collider.gameObject.GetComponent<Rigidbody>();
if (rb.velocity.magnitude > otherRB.velocity.magnitude)
{
if (Mathf.Abs(rb.velocity.magnitude - deviceL.velocity.magnitude) > Mathf.Abs(rb.velocity.magnitude - deviceR.velocity.magnitude))
{
MotherScript2.booleanR = true;
}
else
{
MotherScript2.booleanL = true;
}
}
}
}
}
}
Here is a place where the function ReleaseCube() is called:
else if (PickUpJoint != null || boolean == true)
{
if (BlockP.gameObject.GetComponent<Held>().isHeld() == true)
{
if (trackedController.triggerPressed == false || boolean == true)
{
ReleaseCube(controller);
}
}
} //Remove Fixed Joint and Release Cube
Here is the ReleaseCube function:
public void ReleaseCube(Transform controller)
{
index = (int)trackedController.controllerIndex;
var device = SteamVR_Controller.Input(index);
Debug.Log("Test");
GameObject go = PickUpJoint.gameObject;
Rigidbody rigidbody = go.GetComponent<Rigidbody>();
Object.Destroy(PickUpJoint);
PickUpJoint = null;
SetIsHeld(false, "OnTriggerStay in " + controller.gameObject.name);
BlockP.gameObject.GetComponent<Held>().isCarried(false);
this.SetIsHolding(false, "OnTriggerStay in " + this.gameObject.name);
BlockCounter--;
var origin = trackedObj.origin ? trackedObj.origin : trackedObj.transform.parent;
if (origin != null)
{
rigidbody.velocity = origin.TransformVector(device.velocity);
rigidbody.angularVelocity = origin.TransformVector(device.angularVelocity);
}
else
{
rigidbody.velocity = device.velocity;
rigidbody.angularVelocity = device.angularVelocity;
}
rigidbody.maxAngularVelocity = rigidbody.angularVelocity.magnitude;
}
Sorry for the confusing code. Here is what it does/is supposed to do:
The first part detects collisions between two carried cubes and finds which one is moving faster and what controller it is held by. It then sets a boolean true (the boolean is set false constantly in an update loop).
The second part checks to see if the cube is being held and the trigger isn't pressed or if the boolean is true. It then calls the ReleaseCube function.
The third part destroys the joint between the controller and the cube, sets a bunch of variables that say the cube is held to false, and sets the cube's velocity to equal that of the controller.collisioncollidercubecollision detectiononcollisionenterTue, 02 Aug 2016 01:13:16 GMTrish209Alternatives to OnTriggerEnter and onCollisionEnterhttp://answers.unity3d.com/questions/1223459/alternatives-to-ontriggerenter-and-oncollisionente.html
Hello...
I'm trying to find out if there are any alternatives to OnTriggerEnter and onCollisionEnter
i have used them both in the same set of code already and i get a message up saying that they are already defined and are told to rename the member or use different parameter types
I don't want to have to open a new c# script in order to do this so is there an alternative?
Thank youontriggerenteroncollisionenterSun, 31 Jul 2016 15:58:51 GMTNosmoi want to play a animation on collison . do i need to use a animatore or cani just use the on collision function etchttp://answers.unity3d.com/questions/1223372/i-want-to-play-a-animation-on-collison-do-i-need-t.html
i want to play a animation on collison . do i need to use a animatore or cani just use the on collision function etc
when do u need to use the animator?oncollisionenterSun, 31 Jul 2016 12:07:57 GMTsid4problem with OnCollisionEnter & Exit.http://answers.unity3d.com/questions/1219865/problem-with-oncollisionenter-exit.html
for some reason the debug code never activates:
using UnityEngine;
using System.Collections;
public class player_movement : MonoBehaviour {
private Rigidbody2D player;
private bool touching;
void Start()
{
player = GetComponent<Rigidbody2D>();
touching = true;
}
void OnCollisionEnter()
{
touching = true;
Debug.Log("enter");
}
void OnCollisionExit()
{
touching = false;
Debug.Log("exit");
}
void FixedUpdate ()
{
Debug.Log(Time.fixedTime + " " + touching);
if (Input.GetButtonDown("Jump") && touching == true)
{
player.AddForce(new Vector2(0,15000));
}
}
}
all it ever displays is true. i made sure that both objects have 2Drigidbodys
and colliders but it still doesn't work.oncollisionenteroncollisionexitSat, 23 Jul 2016 11:05:31 GMTguy325Audio script not workinghttp://answers.unity3d.com/questions/1210010/audio-script-not-working.html
I have an audio script to play a little blinking sound when a collectable is picked up. So far I have not managed to get ANY of my audio scripts to play unless the source is set to play on awake. I have the listener on my 3rd person camera, I have the Audio Source attached to the collectable, and I have the assigned sound properly put in. I followed everything off the unity video tutorial but just cant get anything to work. Ive been at this on and off for days. Help would be very appreciated!!
using UnityEngine;
using System.Collections;
public class BingSound : MonoBehaviour {
public AudioClip boing;
private AudioSource source;
// Use this for initialization
void Awake ()
{
source = GetComponent<AudioSource> ();
}
void OnCollisionEnter (Collision coll)
{
source.PlayOneShot (boing, 1F);
}
}audioaudiosourceoncollisionenterFri, 01 Jul 2016 13:52:00 GMTpacocloud