Okay, I have the homing missile implemented. It will follow the player, but I want it to avoid the walls. I tried out A* but I want to make my own. I need some help plzz.
fo me, I am using raycast to create nodes and then use a* algorithm to calculate path. But I am just create some iteration of path since game environment will changed every frame. Here's how I create nodes:
- cast a ray (Physics.raycast) from missile to target, if there's a obstacle get hit point of raycast (usually it's a return value of raycast method).
hitpoint posdivide by
4/8or whatever it's up to u.
- we got a node by execute step 2.
we can repeat step 1 & 2 but this time, we start from the node and we cast some degree to the left or right (the degree is up to u). 5.let's said you cast to the left first, since this cast is not to target, just decide how long you want to cast. 6.same as step 1 & 2. but this time we not cast a ray anymore, just switch it to right direction from first node we've got from step 3. and do the same thing as left in step 5.
now you have 3 nodes! now all you have to do is compare the last two nodes (left & right) because they are branched from the first node, compare who is closest to the target. 8.let's said the result of comparison between left and right nodes is second nodes
- now missile will move to first node and then second nodes
important to note: 1. as this method is not generate path nodes from start to end, missile can't arrive to the target if they reach dead end like maze environment. But I like this method because it's like realistic missile and low cost performance. 2. you can improve it by increase branch nodes per turn.