Quantcast
Channel: Questions in topic: "parenting"
Viewing all articles
Browse latest Browse all 302

GameObject with multiple collider2D,

$
0
0
In my game there are obstacles falling from the top of the screen at different speeds. Obstacles have physics and i'd like to have them interact with eachother (obstacles pushing other obstacles). The problem is that with the collider2D set to Is Trigger, they ignore physics. If i try to ad a second collider2D (of the same type) that isn't set to Is Trigger i can get them to interact but they also interact with the physics of my player (the obstacle is supposed to despawn on collision with player, and it does, but it also move my player physically). I've searched solution in parenting but it is not clear to me how to fix this problem. using System.Collections; using System.Collections.Generic; using UnityEngine; public class Ferro : MonoBehaviour { public float randomSpeedFactor; public int resources; //Risorse date al player private float despawnY = -11; //Limite Y- private ResourceController resourceController; //riferimento alla classe ResourceController private SpeedController speedController; private void Awake() { resourceController = GameObject.FindObjectOfType(); speedController = GameObject.FindObjectOfType(); } private void Start() { randomSpeedFactor = Random.Range(-3, 3); } private void Update() { transform.Translate(Vector2.down * (speedController.speed + randomSpeedFactor) * Time.deltaTime); if (transform.position.y <= despawnY) { Destroy(gameObject); } } void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("Player")) { Debug.Log("Hai raccolto del Ferro"); resourceController.Ferro += resources; Destroy(gameObject); } } } ,

Viewing all articles
Browse latest Browse all 302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>