two colliding objects effect a third object
Stumped in this one. I have a gameobject ( a crane) that animates by rotating as well as its arm going up and down. This is activated by the arrow keys. What I am trying to accomplish is that if , while the crane is rotating, the arm of the crane hits an obstacle ( like an " I" beam) that the turret can not rotate in that direction any more ( forcing you to raise the arm to clear the obstacle) . I have tried putting colliders and triggers on just about everything, setting the animation speed to zero, triggerenter, collider enter etc. I can't put a collider on the component with the animation component because that isn't what collides. I have to put a collider on the joint below that so it will move like the arm does. I think it has to do with the collider on the crane being a child of the part with the actual animation component? So here is the script..while rotating left, if the arm hits an obstacle it turns off the script that enables the turret to rotate that way, if you rotate the other way ( triggerexit) the script goes back on. I have tried CollisionEnter and just about everything I can think of. Please help with ANY advice or comments
using UnityEngine;
using System.Collections;
public class blockCraneRotate : MonoBehaviour {
private MonoBehaviour rotate;
GameObject crane;
GameObject Ibeam;
void Start () {
crane = GameObject.Find("CraneTest");
Ibeam = GameObject.FindWithTag("blockcrane");
rotate = GameObject.Find("CraneTest").GetComponent<CraneLeft>();
}
void OnTriggerEnter(Collider other) {
if(other.tag == "blockcrane")
{
rotate.enabled = false;
}
}
void OnTriggerExit(Collider other) {
if(other.tag == "blockcrane")
{
rotate.enabled = true;
}
}
}
Answer by shadowpuppet · Jul 12, 2016 at 06:20 PM
well I figured it out finally put a rigidbody on the arm of the crane with all constraints checked on, useGravity off. the ibeams have a box collider trigger with the below script. Seems simple now. Could have sworn I tried this as one of my many attempts. Now to add a big metal BANG sound. This script goes on the ibeam to the left of the turret arm. A similar one goes to the rightside to stop rotation going right. Actually each I beam will need two trigger zones...one for the inside, and one on the outside because if you raise the arm to go over the ibeam, then go back from where you came you's need the script that blocks it from that direction as well
using UnityEngine;
using System.Collections;
public class blockCraneRotate : MonoBehaviour {
private MonoBehaviour rotate;
GameObject crane;
Animation anim;
private AudioSource motor;
void Start () {
anim = GameObject.Find("CraneTest").GetComponent<Animation>();
rotate = GameObject.Find("CraneTest").GetComponent<CraneLeft>();
motor= GameObject.Find("CraneTest").GetComponent<AudioSource>();
}
void OnTriggerEnter(Collider other) {
rotate.enabled = false;
anim["craneRotate"].speed = 0f;
motor.Pause();
}
void OnTriggerExit(Collider other) {
rotate.enabled = true;
//anim["craneRotate"].speed = 1f;
}
}
Your answer
Follow this Question
Related Questions
3D Trigger collider slows player moved by forces 0 Answers
onTriggerEnter returns wrong object's attribute 1 Answer
multiple objects with triggers that need to ignore the triggers but still collide with eachother? 0 Answers
Check if character has entered trigger, if it has play animation on character. 1 Answer
Trying to get controller to trigger OnTriggerEnter, no avail 0 Answers