1

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.

artG
  • 235
  • 3
  • 12

1 Answers1

2

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
Almazini
  • 1,825
  • 4
  • 25
  • 48
  • excuse me, but can you give me an example how to pass ball.x values to log? do I need to crate new var in func? I understand how log works, but can't figure out how to imply in to my code – artG Aug 10 '16 at 09:23
  • @artG in your question you are showing end point and swift calculates all points between start point and end point automatically. So you need to create a function with timer in your anyamtion method. E.g. for every 0.1 sec y is changing linearly and x is changing logarithmically – Almazini Aug 10 '16 at 09:27