# scrolling camera / maths help

This forum is currently in read-only mode.
0 Favourites
• 13 posts
• I want to scroll the screen to an object and have it slow to a halt when it reaches it's position, so i set the screen pos to a box, gave the box the ball movement behaviour then set it's speed to the distance between the box's xy and objects xy, but the speed stays constant.

Any help? Thanks.

• You need to "set speed to speed -/+ something." If you "set speed to (distance between stuff)" then it might not behave properly. Try "set speed to speed - (distance between stuff)"

• I don't think that will work because i never know how far away the camera and object is so it's speed might slow to 0 before reaching it, or overshoot.

press a key to move to the next object.

http://www.mediafire.com/?fuend10mejm

I'm still learning construct so maybe theres an easier way i havent discovered yet.

• I edited my post, sorry. I really need to read whole posts instead of just jumping to conclusions.

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• I've fiddled with it for a bit and I can't seem to get it to work the way you want. I'm assuming that you want the box to move faster the farther away from it's target it is? I can't seem to work out how to slow it down from an unknown speed and distance that way.

If I set your box to a constant speed each time I can get it to slow when it's within a certain range of the target, and stop on target, but it starts at the same speed no matter how far away the next target is. And unfortunately if two consecutive targets are very close (within 100 pixels) then the box will overshoot the second.

Sorry, I'm not that good at math. Maybe someone else can help you out.

• Ok fixed i just changed the "Distance(Box.XY,Sprite.XY)" to "Distance(Box.X,Box.Y,Sprite.X,Sprite.Y)"

http://www.mediafire.com/?fjib9tdytm9

• Doppel's suggestion works, but I don't know why using .xy doesn't work (it is meant to!). I'll investigate since it's a bug.

• Ashley maybe becouse the Box.X is just a value and Box.XY is {x,y} for ex. Box.X=20 , Box.XY= {20,50}

• Ok fixed i just changed the "Distance(Box.XY,Sprite.XY)" to "Distance(Box.X,Box.Y,Sprite.X,Sprite.Y)"

http://www.mediafire.com/?fjib9tdytm9

Oi, of course it's something simple like that. I even used (Box.X,Box.Y,Sprite.X,Sprite.Y) to detect distance to slow down my flat-speed test, but I never thought to change it in the action.

Good job, Doppel

• deadeye - yep like they say "The darkest place is under the candlestick."

Also i found quickly solution becouse i was experimenting with .XY function.

• The distance and angle expressions are meant to accept a two-parameter overload with a two-element array {x,y} defining each coordinate so distance(obj1.xy, obj2.xy) would work (as would distance({0,0}, {10,12}), but something seems broken there. It's a slightly quicker way of typing object distances.

• Trust me to always turn up a bug.

Thanks guy's for your help, much appreciated.

On a side note i did try writing it the other way but i must have been entering it in wrong becaus eit keep bringing up a message saying the parameters were wrong.

I know when i start typing in global('whatever') a hint box appears telling me how to complete the command parameters, but this didnt.

Unless i've missed something it would be an enormous help to have an example appear in the expression editor window when you type ina command. As it happens all i had was "distance (distance)", which wasent much help.

• [quote:1afr08yf]Unless i've missed something it would be an enormous help to have an example appear in the expression editor window when you type ina command. As it happens all i had was "distance (distance)", which wasent much help.

That's a bug which is fixed in 0.94. The intellisense doesn't work in 0.93, but in 0.94 is back, and would show distance (x1, y1, x2, y2).