- Home /
How to implement 2D Ai Wandering with 8 - directional movement using Perspective Images in unity 4.3 ???
Hi, My requirement is to move a 2D characters with perspective view images has to wander in game area by choosing dynamic path and according to that the AI character has to switch the
animations based on its current direction and Ai character has to get collision between Ai Character, Ai and Player Character , Ai to Static Obstacles, Moving Obstacles .......
What i done till now is , AI chooses the random Way point and based on its direction it switches the animations and using Ray-cast AI detects the collision with static obstacles, but the problem here is with the Moving Obstacles since AI is casting the ray in one direction, some times AI character was walking on the obstacles like moving cars ..
So please tell me how to solve this problem ???? Thanks in advance
For Better UnderStanding I am giving you the link of what i done so far . If you observe we can find the AI character flickering (that was due to repeated call for choosing new way point )
Here is Link https://dl.dropboxusercontent.com/u/70903877/SuicideBomber/Build.html
Answer by fafase · May 15, 2014 at 09:43 AM
You could a trigger sphere collider attached to the player so when the car enters the collider, you perform an action.
You could get the car to slow down, and the character to either stop if the car is on the front or speed up if he is about to get hit.
Thank u for answer , But I already attached the collider to the AI Character and ray-casting with both the Car and AI character . And when car ray hits AI collider car stops for some time and moves and when AI character ray hits colliders its chooses its new path to move . But problem is I am Ray-cast only in one direction , some times players entering into the Cars Collider
maybe get your raycast to sweep in front of the player. For instance, place three empty game objects attached to the player, one on the front and one on each side by 45 or 90 degrees.
public Transform [] rayPoint;
for(int i = 0; i < rayPoint.Length;i++){
Vector3 direction = rayPoint[i].position - transform.position;
// Use the direction in Raycast
if(raycast){
// Check the i value to deter$$anonymous$$e which has hit
// Do something
}
}
Ya yesterday i tried to rotate the ray in z - direction using the animation clip but i am unable do that .. Could you please tell me how to ray-cast the rays in -45 and 45 degrees to a directional vector where AI character moves. Thanking you for your reponse
Your answer
Follow this Question
Related Questions
What's causing this in my 2D AI script? 0 Answers
Inventory System Unity 0 Answers
Unity 2D Sprites cost many draw calls 1 Answer
Player Vision Radius In a Top Down 2D Game. (Alpha maps?) 2 Answers