The Daily Click ::. Forums ::. Klik Coding Help ::. Determining distance between objects
 

Post Reply  Post Oekaki 
 

Posted By Message

jamesh



Registered
  28/02/2012 15:24:25
Points
  381
5th July, 2012 at 05/07/2012 13:26:21 -

Hi

I want to have a really smooth scrolling camera - a bouncing ball with speed constantly set to the distance it is (in pixels) from the player object.

How can I find the distance between the camera and the player object?

 
n/a

vetmora120



Registered
  07/01/2010
Points
  273
5th July, 2012 at 05/07/2012 13:59:18 -

With the advanced direction object. Alternatively, if you're not keen on using extensions for these sorts of equations, then use the following formula:

Sqr( ( X( "Object 1" ) - X( "Object 2" ) ) pow 2 + ( Y( "Object 1" ) - Y( "Object 2" ) ) pow 2 )

In which case Object 1 would be the camera, and Object 2 would be the player. Or vice versa. Shouldn't which is which in this situation.

 
n/a

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
5th July, 2012 at 05/07/2012 14:12:22 -

Is the camera a separate object?

Distance = Abs(X("Player")-X("Camera"))

Or if you want X and Y scrolling...

Distance = Sqr((X("Player")-X("Camera"))pow 2+(Y("Player")-Y("Camera"))pow 2)

Or if you need the distance between the player and the edge of the window...

Distance from top = Y("Player") - Y Top Frame
Distance from bottom = Y Bottom Frame - Y("Player")
Distance from left = X("Player") - X Left Frame
Distance from right = X Right Frame - X("Player")

 
n/a

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
5th July, 2012 at 05/07/2012 14:31:57 -

Beat me to it.

 
n/a

vetmora120



Registered
  07/01/2010
Points
  273
5th July, 2012 at 05/07/2012 14:56:24 -

Heh. Your response was slightly more elaborate.

 
n/a

nim



Registered
  17/05/2002
Points
  7234
5th July, 2012 at 05/07/2012 16:02:12 -

Download Snippet Manager 2 by Sketchy. It comes with a bunch of useful formulae like this.
http://create-games.com/download.asp?id=8227

 
//

jamesh



Registered
  28/02/2012 15:24:25
Points
  381
5th July, 2012 at 05/07/2012 17:39:30 -


Originally Posted by vetmora120
With the advanced direction object. Alternatively, if you're not keen on using extensions for these sorts of equations, then use the following formula:

Sqr( ( X( "Object 1" ) - X( "Object 2" ) ) pow 2 + ( Y( "Object 1" ) - Y( "Object 2" ) ) pow 2 )

In which case Object 1 would be the camera, and Object 2 would be the player. Or vice versa. Shouldn't which is which in this situation.



This is absolutely magic, it works perfectly! Thanks guys.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click