Hello,
I have run into a little problem that is too advanced for me yet. I hoped somebody could hint me to how to solve this issue.
Problem:
Although my game works fine I am unhappy with the freedom of movement that the unity engine provides to the ball. I don’t like that my ball sometimes goes straight to the right or left. In my version of this game this is extra bad because I made it so that the ball and player can pass the sides and pop up on the other side. In other words I wish to limit horizontal movement.
Objective:
I wish to restrict the angle of the ball. (See image: green–> okay, red–> not okay). Luckily my ball is an image and does not rotate by itself.
Now I need to do 3 things:
-
Determine whether my ball is moving to the right or left (or potentially neither if it moves straight up or down). The only way I can think of doing this is by calculating the current position and comparing that to the position of the previous frame. Are there any better ways/ build in functions?
-
I need to see what angle the ball is making.
-
If it is in the red zone it should be (a bit randomly) tweaked so that the angles comes into the green zone. This I found can be done with:
transform.Rotate (Vector3.forward * X) (where X is the angle you want to rotate the object by.)
Alternatively I could try a clamp on the angle?
Does anyone have an idea how to get closer to achieving the objective? Thanks!