artG artG - 3 months ago 26
iOS Question

How to create realistic ball drop from cliff using swift and UIkit

I try to make the ball with realistic physics when it fall from cliff, as you can see in in image 2. that's what I what to achieve, for now I have what is drawn in image 1.Image of ball phisics

for image 1. I use this code:

ball.center.x += 5
ball.center.y -= 4


By the way, in game cliff is slowly going down and ball up, after ball drops from cliff, cliff stops and ball just drop to the floor.

Question how can I make something like what I draw in image 2. Is there a easy way to do this, because I am not yet a good friend with physics.

Answer

You will need a logarithm function to generate values for x and y You can check more here: theory

After importing UIKIT or FOUNDATION it will be like this in Swift:

func log2(x: Double) -> Double

func log2f(x: Float) -> Float
Comments