Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / RTS Camera Controls

Author
Message
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 2nd Feb 2013 20:00
Im trying to come up with a way to move the camera around in 3d space. I know all the camera controls like position camera and camera angle x etc etc but i am struggling to come up with a way to make the camera move when the mouse is almost off the screen.
I have set up a plane with a texture to represent the map and want the camera to start off at a specific position which i think with enough tweaking i can manage but then moving it (including zooming in and out) is proving difficult. I can do it with the arrow keys but don't know what the coordinates are for each edge of the screen depending on where in the game world the camera is. Can anyone help?
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Feb 2013 23:26
You mean scroll the camera around when placing the mouse around the edges of the screen?



"You're not going crazy. You're going sane in a crazy world!" ~Tick
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 4th Feb 2013 09:00
Thanks, i was getting some odd results using position camera (which i was doing wrong anyway) and couldn't think how to resolve it, this works perfectly.

What i certainly can't get right at the moment is the mouseZ() to zoom. Its not smooth enough nor do i know what figures to use to cap it at a certain distance zoomed in or out (i.e lock it between 2 certain points so it cant go further.)

I am going to try and use 2d pictures as buildings on a textured plane which i intend to break up into a grid using an array somehow. Now i think the grid array will resize with the zooming in and out but if i select a building it automatically becomes the mouse cursor till its been placed but im not sure it will retain its size dependent on zoom level. Im not sure how to get round that one.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 4th Feb 2013 17:24 Edited at: 4th Feb 2013 17:48
This is the simplest way to do it:



Or you make it smoother by updating the zoom amount over time:


What this does is actually updates the camera's zoom 12 times for every wheel scroll, but the amount that it zooms in decreases. Flick the mouse wheel once, and the first speed value to zoom in/out by is 6. That value decreases by one and so the next time it zooms by 5.5, then 5, then 4.5, etc... Once it reaches 0 it'll stop zooming. Basically, it zooms it quick at first that gradually slows down.

"You're not going crazy. You're going sane in a crazy world!" ~Tick
zeroSlave
15
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 4th Feb 2013 20:45 Edited at: 6th Feb 2013 01:40
Don't forget about CURVEVALUE(Destination Value, Current Value, Speed Value) It doesn't really work (that I know of) with timer based movement, but if the sync is fixed, it'll give decent results.

Here is an example of a 3D RTS camera style control. There are probably better ways of doing it, but this may give you something fun to look at. It zooms smoothly. Allows for WASD and mouse-screen-edges to control the camera's location. It has a little modifier to increase camera speed according to how far it's zoomed out. Has minimum and maximum zoom levels, as well as the camera's up/down angle.





Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 5th Feb 2013 19:49 Edited at: 5th Feb 2013 19:50
You got many options there. I'll throw in a few more examples for additional learning.

Without Matrix1.


With Matrix1:


Limited with Matrix1:


Login to post a reply

Server time is: 2024-11-23 18:14:48
Your offset time is: 2024-11-23 18:14:48