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.

Code Snippets / Camera Control Function | 1st, 2nd, 3rd Person View | Effects, and More!

Author
Message
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 30th Oct 2005 19:53 Edited at: 31st Oct 2005 04:34
Camera Control Function
Created By RUCCUS


Note: The old thread title didn't suit the function, seeing as the function serves multiple camera controls and the old thread was entitled 3rd Person View Function, the old thread will be locked: http://forum.thegamecreators.com/?m=forum_view&t=63718&b=6

Use this function in your games for fast and easy camera control. It allows you to set a wide variety of variables to suit your needs. All you need to do is include the function in your program and call it once and it will handle everything else; just follow the simple instructions at the end of the post.

Great for any camera view you can think of, there's a sample at the bottom of this post containing 5 different views made using the function; 1st person view, 2nd person view, 3rd person view flying style, 3rd person view walking style, and 3rd person view map editor style w/ scroll button zooming.

There's a lot of parameters but after using it for a while you'll get used to it and adding it will become a cinch.

Features:

Easy implementation
Mouse/Camera rotation option
Mouse/Object rotation option
Camera rotation limits
Camera rotation speed
Customizable camera positioning and tilting
Easy zooming implementation

Syntax:

ThirdPersonView(Object, Dummy, Mesh, X, Y, Z, Tilt, Speed, DumX, DumY, ObjX, ObjY, MaxUp, MaxDown, MaxLeft, MaxRight)

Breakdown:

Object: The Object you wish to have 3rd Person View applied to.

Dummy: A "Dummy" object used for camera control. Specify this object number as an object not created in the game yet, the function will create the object using the dummy number.

Mesh: An uncreated mesh number that the function can use to add limbs with.

X: X offset for the camera; how far left or right of the user the camera will be.

Y: Y offset for the camera; how high or low the camera will be.

Z: Z offset for the camera; how close or far from the object the camera will be.

XTilt: The angle offset for the camera on the x axis, how far left or right of the object the camera should point.

YTilt: The angle offset for the camera on the y axis, how far above or below the object the camera should point.

ZTilt: The angle offset for the camera on the z axis, how far infront or behind the object the camera should point.

Speed: The speed at which the mouse rotates the camera and object. It's recommended setting this to a decimal (.1 works good). Setting this to 0 will cancel out the mouse rotation code, incase you don't want to use the mouse.

DumX: Set this parameter to 1 if you wish the mouse to rotate the camera around the x axis of the object.

DumY: Set this parameter to 1 if you wish the mouse to rotate the camera around the y axis of the object.

ObjX: Set this parameter to 1 if you wish the mouse to rotate the object around it's x axis as the mouse moves.

ObjY: Set this parameter to 1 if you wish the mouse to rotate the object around it's y axis as the mouse moves.

MaxUp: The Max upward rotation of the object/camera. Setting this to 0 will give no limits. Set this to a negative number.

MaxDown: The Max downward rotation of the object/camera. Setting this to 0 will give no limits. Set this to a positive number.

MaxRight: The Max rotation to the right the object/camera can go. Setting this to 0 will give no limits. Set this to a negative number.

MaxLeft: The Max rotation to the left the object/camera can go. Setting this to 0 will give no limits. Set this to a positive number.

Function Source Code:



Sample Code:

Here's some sample code on how to use the function. Alter it to experiment before implementing it into your game, press buttons 1 - 5 to switch between the views included in the program.



Add-Ons

Feel free to suggest any add-on features for the function. Critisism is encouraged, questions are welcomed. If the suggestion sounds good or the bug is legitimate I'll correct/add it as soon as possible.

Other than that, Enjoy

RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 30th Oct 2005 22:14
Nice work Ruccus!
We could use some code like this in the Open MMORPG Project. Would you mind?


Open MMORPG: It's your game!
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 30th Oct 2005 23:47 Edited at: 31st Oct 2005 04:34
Not at all, I'm flattered

P.S Was that a request for just the use of the function or a request for me to exclusively program it for the game so you don't have any of the extra if's then's in there, just the code you need.

Either way yes and yes

RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 31st Oct 2005 00:02
Well, we have some camera control code as well. It does some other things, like avoids terrain. You might find that usefull as well. So either way - thanks and thanks!


Open MMORPG: It's your game!
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 31st Oct 2005 00:37 Edited at: 31st Oct 2005 04:33
Just posted on your forums and I read about what you've got if it's doing the trick then thats great but I'm still going to program a function to do what you guys are asking for just incase, it'll help me learn more either way.

RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 31st Oct 2005 16:28
Thanks for the help Ruccus!


Open MMORPG: It's your game!
Anto
19
Years of Service
User Offline
Joined: 30th Oct 2005
Location: Brisbane, AUS
Posted: 1st Nov 2005 05:01
RUCCUS,

Is it made for DBC or DBP? as i tried to run it in DBC 1.13, won't run, it stops at "CameraContorl"

it supposed to read the function.. but it won't

Anto
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 3rd Nov 2005 04:19 Edited at: 3rd Nov 2005 04:20
I dont have DBC but here's a list of all the commands it uses, if you spot one DBC doesnt like then please tell me:

Commands the function uses:

FUNCTION()
OBJECT EXIST()
DIM()
MAKE OBJECT TRIANGLE
MAKE MESH FROM OBJECT
ADD LIMB
DELETE MESH
OFFSET LIMB
POSITION CAMERA
POINT CAMERA
OBJECT POSITION X()
OBJECT POSITION Y()
OBJECT POSITION Z()
LIMB POSITION X()
LIMB POSITION Y()
LIMB POSITION Z()
POSITION OBJECT
XROTATE CAMERA
YROTATE CAMERA
MOUSEMOVEX()
MOUSEMOVEY()
XROTATE OBJECT
YROTATE OBJECT Dummy,CamY#(0)
INC

Opperators the function uses:

+
-
=
>
<
(
)
#

From my knowledge I haven't heard of DBC not having any of those commands so it's strange that it wouldnt work, maybe you missed a parameter, there's quite a lot of parameters so it's easy to miss one I've fone it a few times.

Whats the error message you're getting?

Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 4th Nov 2005 19:31 Edited at: 4th Nov 2005 19:31
When calling a function, all paremeters have to be of that type. And for DBC 120 is an integer and not a double.
If you put .0 after each number in the call that has to be a double, problem solved.

Also, you might need to use wrapvalue(). DBP wraps this automatic, but DBC gives an error instead.

Finally, move object right and left are commands that are not available in DBC.

That was all

Cheers

Sven

Immunity and Annihalation makes Immunihalation...
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 8th Nov 2005 03:42
Thanks Ill try and fix it up when I have time.

All Makes Combined
19
Years of Service
User Offline
Joined: 13th Nov 2005
Location: DFW, TX
Posted: 14th Nov 2005 03:05
I've been looking everywhere, and I cen't seem to find an example that helps me for my freeflight spacesim. Yours is the closest I have. It's only missing Z rotation or roll.

The object is controlled using pitch and roll commands. The reason is, that the pivots/heirarchy wont follow the object using x/y/x rotate.

Is there a way to have the camera follow like the 3rd person (flying) and/or 1st person views you have here, but include rolling (zrotation)..?

This is SO close to what I need. Thank you for what you have so far.

Login to post a reply

Server time is: 2024-11-23 10:36:36
Your offset time is: 2024-11-23 10:36:36