I gave the player a collider to play role of hand
If a collision happened between the hand and the truck and player pressed E the player should be able to drive the truck but the weird thing is that sometimes the truck recognize the collision sometime not?
why?
OnCollisionStay updates at the same rate as FixedUpdate and so GetKeyDown will be unreliable because it’s meant to be used in Update.
A rigidbody will quickly go to sleep if it’s not moving and will no longer trigger OnCollisionStay.
Please stop making duplicate posts for the same issue; this is the 3rd post. Please create a single thread for working on something.
I’ll close the other thread because you don’t show anything related to the ECS system. If it is ECS then you’re in the wrong forum with this duplicate post.
Thanks.
I added a cube only have a BoxCollider to test it with the switch " https://discussions.unity.com/t/943297 " but the collision is not detected by the switch
switch script
you said that collision don’t work with the character controller but I have this script for a car and its working fine
Its Look like I don’t undrstand how this onCollision… work
the code you give me is working find thanks
void Update()
{
if (Input.GetKeyDown(KeyCode.E))
{
Collider[] colliders=Physics.OverlapSphere(transform.position,10); // get the nearby colliders
foreach(Collider c in colliders)
{
if (c.gameObject.CompareTag("lamp"))
c.gameObject.SetActive(!c.gameObject.activeSelf);
}
}
}
It works because there’s a rigidbody present. OnCollision is for rigidbody related collisions but it doesn’t work with character controller. OnTrigger works with both character controller and rigidbody.
Or if you want to detect collisions with solid objects when using the character controller then you should use:
void OnControllerColliderHit(ControllerColliderHit hit)
{
Debug.Log(hit.collider.name);
}
It’s all very confusing.
Thanks for your help