Smooth mouse view

For questions about using Classic.

Post » Sun Nov 30, 2008 8:37 pm

I will try to explain...

I am making a RTS game, and I need a smooth camera movement (moving around with no imediately action or fast action, need smooth camera) like in other RTS games like: Warcraft, Starcraft etc. or like 3D tool programs, when you hold the right button and move, it's like an acelerating method.

I am having trouble with the "Center view on me", because it's too fast, and it is imediately, i need something more dynamic. Can anybody help-me pls?

Thanks and sorry for my english!
B
4
G
4
Posts: 27
Reputation: 1,179

Post » Sun Nov 30, 2008 9:08 pm

One trick for smooth scrolling is to scroll always to the halfway of current point and target point. This way it scrolls first wast and then slows down when appoarching the target point.

Pseudocode:

scroll x to current.x + ((target.x - current.x )/2)
scroll y to current.y + ((target.y - current.y )/2)

If you want more snappy and quick scrolling, just change the 2 to some bigger number.
B
3
S
2
G
5
Posts: 263
Reputation: 2,201

Post » Sun Nov 30, 2008 9:22 pm

Sorry but can you make a little example?
I am trying use your code in construct, but it doesn't work for me


ps: I need the camera to follow the mouse, but in smooth condition

:/

[EDIT]

THANKS DRASA, I HAVE USED YOUR CODE CORRECTLY, IT'S WORKED PERFECTLY, THANKS!!!!
B
4
G
4
Posts: 27
Reputation: 1,179

Post » Sun Nov 30, 2008 10:01 pm

Oh, I made a mistake :D. The scrolling becomes actually slower when you increase the number.

Also, I whipped up an example, but it seems there's no need for it anymore.

[url:ju8eqfkk]http://drasa.nipponfever.net/muu/rts-scroll.cap[/url:ju8eqfkk]
B
3
S
2
G
5
Posts: 263
Reputation: 2,201

Post » Sun Nov 30, 2008 10:09 pm

That's a good example, but it's framerate dependent. If you run at twice the framerate, you move twice as quickly towards the scroll location. That might not matter that much for scrolling, but if you want the same thing for important gameplay elements, this is the framerate independent formula:

lerp(ScrollY, Sprite2.Y, 1 - 0.0001 ^ TimeDelta)

0.0001 is the number to change for how quickly it goes. Smaller makes it go faster.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,518


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest