- Home /
suggesting the ball to safe direction off being hit using guitexture
Hii Since i am working with a ball game & looking for some good solution for below problem.
the enemy ball move randomly around the scene if enemy balls coming closure to player ball then we need to suggest the safe direction to the player ball by displaying the guitexture arrows like left,right,up,down like that......Eg: if enemy balls are moving closure to player ball in +z axis then the arrow should suggest the safe direction either left or right.
Thanks!!!!
Answer by Berenger · Jun 30, 2012 at 08:43 PM
The escape direction is going to be the cross vector between up and player -> enemy.You should check if the direction is avalaible (no walls) and if it's not, invert it.
Answer by AlucardJay · Jun 30, 2012 at 09:08 PM
This is an easy way to check which object is closer, and what side of the player the object is on. You can attach this script to any gameObject (or the camera), then drag-and-drop the player and enemies into the Inspector.
#pragma strict
public var Player : Transform;
public var Ball_1 : Transform;
public var Ball_2 : Transform;
private var closestBall : Transform;
private var goLeft : String = "Go Left";
private var goRight : String = "Go Right";
private var guiString : String = "";
function Update()
{
if ( (Ball_1.position - Player.position).magnitude < (Ball_2.position - Player.position).magnitude )
{
closestBall = Ball_1;
}
else
{
closestBall = Ball_2;
}
if (Player.position.x < closestBall.position.x)
{
guiString = goLeft;
}
else
{
guiString = goRight;
}
}
function OnGUI()
{
GUI.Box(Rect((Screen.width/2) - 50, 10, 100, 30), guiString);
}
http://docs.unity3d.com/Documentation/ScriptReference/Vector3-magnitude.html
@alucardj: Thanks for the help....pls check the below doubt http://answers.unity3d.com/questions/277983/activate-animation-on-android-device-rotation.html
If your question has been answered, please mark it =]
Left of the answer, there is a : Thumb Up : a number : Thumb Down : Tick(check) $$anonymous$$ark :
Please tick the answer you have accepted, as it helps people in future searching the 'site and reading questions. Also good to know that you have an answer that worked, and gives you and the person karma points !
I work with iOS, not Android, but I shall take a look at the question. I am just starting out myself, and have learned alot from the many other helpful people here, so if your question is good you should have no trouble getting some answers. Good Luck and Have Fun =]
@alucardj: how can i add the destination like placing a box and adding that game object as a destination & the arrows should guide the safe way off being hit to the player to reach that location.
Thanks for ur help buddy.....i really wanna hit thumb up but i am restricted i mean i can't hit thumb up now for that i need to create a new a/c which i am about to create....