#httpsdocs unity3d
1 messages · Page 1 of 1 (latest)
Tried it. It only works if the passing is caused by movement being too fast to be detected between the frames, and in this case it's a completely different issue - the crosshair is given a new velocity vector as soon as it touches the collider, but if the velocity vector points inside the collider, it will enter anyway.
At this point:
- if i use OnTriggerEnter, that's it - it's already inside the collider and will come out on the other side (unless I use an extra OnTriggerExit, in which case it might instead get stuck "inside" the Wall, making the issue worse than in 2.)
- if i use OnTriggerStay, it'll be given a new velocity vector next frame - which may push it back into the shooting gallery or, more likely, will keep it inside the wall, and it will repeat every frame, until it finally jitters out on either side of the collider (more likely inside, since it's closer, but still)
i guess I could add separate tags on X and Y aligned walls, and write separate scripts for them, but if I introduce a different kind of obstacles later, it won't work at all
Another issue: I checked if just stopping the crosshair on hitting the wall will stop it literally on contact. Nope. Depending on its movement speed, it becomes embedded at different depths in the wall.
I changed the code to "disembed" the crosshair from the wall on enter, and then bounce on exit:
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Wall"))
{
crosshairRb.velocity = -crosshairRb.velocity;
}
}
private void OnTriggerExit(Collider other)
{
if (other.CompareTag("Wall"))
{
BounceCrosshair();
}
}
but now it jitters as it backtracks from the wall. I tried increasing the backtracking speed, but it looks unnatural, like it snaps the crosshair instantly into the space inside the gallery