why OnTriggerEnter is not work if with void Update
Hay.. i new comer. i have question i try a cube move headed for boxCollider but not something happen and debug not come out to consol, then among two of them have Rigidbody. Thanks in advance
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Jalan : MonoBehaviour
{
int speed = 4;
public bool noSpeed;
Rigidbody cubeRB;
// Start is called before the first frame update
void Start()
{
cubeRB = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
if( noSpeed == false)
{
MoveCube();
}
}
void OnTriggerEnter(Collider other)
{
if ((other.gameObject.CompareTag("BOXCOLLERD")) && noSpeed == true)
{
Debug.Log("Hiit");
cubeRB.transform.position += Vector3.zero;
}
}
void MoveCube()
{
cubeRB.transform.position += Vector3.right * speed * Time.deltaTime;
}
}
Can you post a screenshot of the rigidbody component and box collider component of the cube as well?
Answer by lgarczyn · Jan 14, 2020 at 08:31 PM
You can't move a rigidbody using transform.
If you want a collision, you need to use AddForce in the direction you want it to move.
i mean how to stop cube if cube to Trigger box collider... but not expected cube move keep going since trigger box collider
If you want your cube to collider with things, it can't be kinematic or trigger.
i not understand. but among bot of them have rigidbody if happen is trigger.
Answer by LeonardSchoyen · Jan 14, 2020 at 06:25 PM
Possible problems:
Cube doesn't have a collider component
You're not moving rigidbodies the way they are meant to be moved – with rigidbody.velocity or rigidbody.AddForce(...)