Hi I'm trying to add something into my game that zooms out the camera the faster the ball moves, and zooms in if it slows down. This is what I managed to make.
global time as float = 0
global steptime as float = 0
global timerstat as float = 0
global timerdistance as float = 0
global distancevalue as float = 0
global zoomvalue as float = 0
global zoom as float = 1
global zoomminus as float = 0.002
timerpositioner = createsprite(0)
zoomvalue = distancevalue/130
zoom = zoom - zoomvalue
SetViewZoom(zoom)
if zoom < 0.9
zoom = 0.9
endif
timerdistance = Sqrt( (GetSpriteX(timerpositioner) - GetSpriteX(ball))^2 + (GetSpriteY(timerpositioner) - GetSpriteY(ball))^2 )
time = timer()
if time > 0.01
SetSpritePosition(timerpositioner,GetSpriteX(ball),GetSpriteY(ball))
distancevalue = timerdistance
ResetTimer()
endif
So to explain:
Variable Declaration
global time as float = 0
global steptime as float = 0
global timerstat as float = 0
global timerdistance as float = 0
global distancevalue as float = 0
global zoomvalue as float = 0
global zoom as float = 1
global zoomminus as float = 0.002
This is a formula that checks the distance between two objects.
timerdistance = Sqrt( (GetSpriteX(timerpositioner) - GetSpriteX(ball))^2 + (GetSpriteY(timerpositioner) - GetSpriteY(ball))^2 )
This is a timer that every 1/100th of a second teleports to the balls current position and saves the speed at which the ball is going at.
time = timer()
if time > 0.01
SetSpritePosition(timerpositioner,GetSpriteX(ball),GetSpriteY(ball))
distancevalue = timerdistance
ResetTimer()
endif
This here processes the current speed as a float for how far the game should zoom out, as well as setting the view and adding a limit
zoomvalue = distancevalue/130
zoom = zoom - zoomvalue
SetViewZoom(zoom)
if zoom < 0.9
zoom = 0.9
endif
Yes I know to more experienced people this may seem like an absolute disaster, but we're all here to learn.
If anyone has a solution, or has created this before in their own code I would be super thankful if someone could help me out.
Thank you.