Hello all, im making soccer game for smartphones. My question is how to limit player to kick the ball within goal limit? Please look at the following attachment
Sorry for my poor English
Hello all, im making soccer game for smartphones. My question is how to limit player to kick the ball within goal limit? Please look at the following attachment
Sorry for my poor English
Colliders? You might need to explain yourself better.
I want to limit the shoot target, Player always shoot within goal post.
I want somthing similar to this,
Quaternion targetRotation = Quaternion.LookRotation (goalPosition.position - transform.position);
transform.rotation = targetRotation;
I’m also not clear on what your asking but based on the code snippet I don’t think your asking how to detect when the ball enters the net (as mentioned colliders is probably easiest for that). Are you asking how to have your player always shoot the ball towards the goal (in that direction)? If so I think more details are still probably needed.
Not quite sure the specific question you’re after.
Please look at following screenshot, I want Player to kick the ball toward goal post.
This following code works properly, but problem is player kick the ball always in same direction. Player can kick anywhere he want but within goal post.
if(Shoot) {
Quaternion targetRotation = Quaternion.LookRotation (goalPosition.position - transform.position);
transform.rotation = targetRotation;
ball.gameObject.GetComponent().velocity = new Vector3(transform.forward.x30.0f, 5.0f, transform.forward.z30.0f );
}
You may want to find a way to slightly randomize the position of goalPosition.
not random actually,
if player rotation is toward goal post then add forward velocity in a ball,
else if Player rotation exceed goal then limit player rotation
If the player can actually choose the point where the ball is kicked, that’s quite different.
You could check if the selected point (when projected into world space) lies somewhere inside the edges of the goal. Or you could add a box collider trigger to the goal and do a raycast in the player’s direction from the ball’s position and check for a hit against the box collider.
I solved it by keeping Cube inside the goal.
Position of cube is controlled by player rotation and cube is limited inside the edges of the goal. then i used following code and it worked
if(Shoot) {
Quaternion targetRotation = Quaternion.LookRotation (cube.transform.position - transform.position);
transform.rotation = targetRotation;
ball.gameObject.GetComponent().velocity = new Vector3(transform.forward.x30.0f, 5.0f, transform.forward.z30.0f );
}
Thank you all