I'm trying to make game like portal which players can transform between two holes.
My problem is, how to detect if player's have the right angle to the hole. (hole has an angle to a direction, if player's angle to hole meet the right direction can do transform)
Pseudo code:
var range=30;
if(collission){
if(abs(ball.getAngle()-player.getAngle())<=range){
ball.doTransform(player);
}
}
below is some situation:
ball.setAngle(20);
player.setAngle(30);
abs(ball.getAngle()-player.getAngle()) ==10 //ok
player.setAngle(350);
abs(ball.getAngle()-player.getAngle()) ==320 //not ok
ball.setAngle(350);
player.setAngle(20);
abs(ball.getAngle()-player.getAngle()) ==330 //not ok
ball.setAngle(120);
player.setAngle(100);
abs(ball.getAngle()-player.getAngle()) ==20 //ok
and anybody can help me to figure out the right condition so that ball can transform player? thanks!
range
variable? What is the difference betweenplayer
andball
? Why compare the player's angle with the ball's and the hole's? This way you couple the player with both ball and hole, don't you want to take care only of how the player "faces" the hole? (disregarding other objects). Rephrasing the question a bit might help us giving an answer. \$\endgroup\$