- Home /
Destroy plane behind character controller or camera
I have a character controller which is running through planes.
Loading 20 planes for my game.
I want to destroy last plane where character controller stands.
Raycast makes high memory
Which is the best method to use this?
Answer by cdrandin · Aug 02, 2013 at 04:33 AM
Use Vector math and trigger events. If the normal of the CC is point in the Z-axis for this example. Then in order to tell if the plane is behind the CC would be for the normal of the plane to be pointing in the opposite direction of the player. Something like this
Thus we can tell the CC is behind in plane, but we don't want this for every time the plane is behind the player for no reason. So only check this for the case, the plane leave the collider of the CC. Therefore you could use Unity's OnTriggerExit function.
Here is an example of this http://www.youtube.com/watch?v=Q9FZllr6-wY&list=PLW3Zl3wyJwWOpdhYedlD-yCB7WQoHf-$$anonymous$$y∈dex=9
Which uses Dot Products. The video explains the offsets for the dot product because it is very hard to achieve normals to be perfectly parallel using the dot product, so leave some wiggle room.
Your answer
Follow this Question
Related Questions
Object Does not Destroyed While Shooting 1 Answer
How to diappear a line renderer from start and end position of line 1 Answer
A node in a childnode? 1 Answer
Continuous detection of object using ray cast 2 Answers
Destroy and Instantiate 2 Answers