#Make a Trigger that only triggers one specific Object

8 messages · Page 1 of 1 (latest)

dapper glacierBOT
#

It's hard to answer a programming question without code

Resolving a bug is almost impossible when the question doesn't include any of the buggy code. In order to help fix the problem, answerers are going to have to see what the code is.
Source: https://idownvotedbecau.se/nocode

Please isolate the problematic code and send it as a codeblock. If you don't know how to send a codeblock, type []cb

empty quartz
#

[public class RocketScript : MonoBehaviour
{
private Rigidbody2D rb;
public Transform playerTarget;
public float speed = 5;
public float rotateSpeed = 200f;
public GameObject explosionEffect;
public GameObject PlayerObject;
public FreeFallGameManagerScriipt mainscript;
public bool rocketActive = false;
private void Start()
{
rb = GetComponent<Rigidbody2D>();
}
private void FixedUpdate()
{
if (rocketActive)
{
Vector2 direction = (Vector2)playerTarget.position - rb.position;
direction.Normalize();
float rotateAmount = Vector3.Cross(direction, transform.up).z;
rb.angularVelocity = -rotateAmount * rotateSpeed;
rb.velocity = transform.up * speed;
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (rocketActive)
{
Instantiate(explosionEffect, transform.position, transform.rotation);
mainscript.playerdeath();
Destroy(gameObject);
PlayerObject.SetActive(false);
}
}
}] Code Rocket

#

using UnityEngine;

public class TriggerScript : MonoBehaviour
{
public RocketScript script;
private void OnTriggerEnter2D(Collider2D collision)
{
script.rocketActive = true;
}
} []cb

#

Thats the Triggerobject, which has an collider set to trigger

#

NVM it works as i wanted

frail sparrow
#

The bot clearly says to find out how to make one, to type []cb, as in:

#

[]cb