SA-MP Forums [Tutorial] How to make a rotating camera on class selection
 New Account Members List Search Today's Posts Mark Forums Read

 22/10/2011, 12:45 AM #1 Lorenc_ High-roller     Join Date: Jan 2010 Location: Australia Posts: 4,174 Reputation: 983 How to make a rotating camera on class selection A tutorial to creating camera rotating Why? What? Why'd you make this? Out of boredom, I decided to make a class rotating camera tutorial. Would be nice for A/D servers to have such a feature. What you'll need in this tutorial:A little bit about trignometry (using COS, SIN) A brain (which you all have :P) Okay, note that this is not even close to what Dice7 wrote a long time ago on his class rotating camera selection. So yeah, don't say it is. The camera rotates around the player and goes by the circumference of this circle. Some options are tweak-able to adjust the camera though you must get rid of your current camera inside of your gamemode before using. Basic structure - Diagram Lets script! Variables Using variables/constants looks more neater than defining for me (yes, I'm creating some 32 bit variables facepalm.jpg) Code: ```/* ** Server Data ** */ const // Constant values, you may change it to "new" if they're going to be modified once rotating. Float: spawnX = 0.0, // The SPAWN X you're willing to work from Float: spawnY = 0.0, // The SPAWN Y you're willing to work from Float: spawnZ = 5.0, // The SPAWN Y you're willing to work from Float: camRadius = 20.0, // The radius of the camera rotating Float: camSpeed = 1.25, // The speed of the camera moving around. MUST NOT BE NULL; IT WONT MOVE IF SO! Float: camHeight = 6.0 // The height of the camera once moving! ; /* ** Player Data ** */ new prc_Timer [MAX_PLAYERS], // The timer for the movement. bool: prc_Moving [MAX_PLAYERS], // Check if the player is moving his camera Float: prc_Degree [MAX_PLAYERS] // The degree counter to show which the player is on. ; forward MoveCamera(playerid); // We'll add this here to prevent future warnings..``` OnPlayerRequestClass Code: ```public OnPlayerRequestClass(playerid, classid) { SetPlayerPos(playerid, spawnX, spawnY, spawnZ); // Set the player at those 3 const spawn values from before. if(prc_Moving[playerid] == false) // Check whether the camera is already set. { prc_Degree[playerid] = 0; // Reseting the variable prc_Timer[playerid] = SetTimerEx("MoveCamera", 75, true, "d", playerid); // Setting the timer prc_Moving[playerid] = true; // okay, now we're going to activate the moving variable } return 1; }``` Camera movement Code: ```public MoveCamera(playerid) // The core of the movement { static // Static for the repeation :O Float: nX, // The newX Float: nY // the newY ; if(prc_Moving[playerid] == false) // check whether the timer is activated and the variable isn't. { KillTimer(prc_Timer[playerid]); // Killing the timer, ofc we don't want a 75 ms timer always running. prc_Degree[playerid] = 0; // Reseting the variable } if(prc_Degree[playerid] >= 360) prc_Degree[playerid] = 0; // If the rotation is past 360, reset to 0 (looks more neater) prc_Degree[playerid] += camSpeed; // For some smooth rotation, I'm using 1.25 nX = spawnX + camRadius * floatcos(prc_Degree[playerid], degrees); nY = spawnY + camRadius * floatsin(prc_Degree[playerid], degrees); // So, we're going to get the spawn axis and add the radius in to them. // Then we use the trignometric functions to apply such angles to the movement // making it look nice. SetPlayerCameraPos(playerid, nX, nY, spawnZ + camHeight); // Setting the Camera position around the player SetPlayerCameraLookAt(playerid, spawnX, spawnY, spawnZ); // Looking at the player position from there :) SetPlayerFacingAngle(playerid, prc_Degree[playerid] - 90.0); // to make it face the camera :) return 1; }``` OnPlayerDisconnect Code: ```public OnPlayerDisconnect(playerid, reason) { if(prc_Moving[playerid] == true) { KillTimer(prc_Timer[playerid]); // Killing the timer, ofc we don't want a 75 ms timer always running. prc_Degree[playerid] = 0; // Reseting the variable prc_Moving[playerid] = false; // Reseting the variable } return 1; }``` OnPlayerSpawn Code: ```public OnPlayerSpawn(playerid) { if(prc_Moving[playerid] == true) { KillTimer(prc_Timer[playerid]); // Killing the timer, ofc we don't want a 75 ms timer always running. prc_Degree[playerid] = 0; // Reseting the variable prc_Moving[playerid] = false; // Reseting the variable SetCameraBehindPlayer(playerid); // Preventing bugs from appearing. } return 1; }``` Screenshots I rather have screenies than a video, since youtube wrecks the video quality for me - Uploaded with imageShack, sorry for people that cannot view it! Download Example gamemode with the default structure Problems? If there is any problems which mostly said not to be, please report them and I'll fix them. Last edited by Lorenc_; 22/10/2011 at 07:55 AM.
 22/10/2011, 12:49 AM #2 ©•Riddy•© Little Clucker     Join Date: Oct 2011 Posts: 3 Reputation: 11 Re: How to make a rotating camera on class selection Looking good Lorenc, Gonna use it on BlackOps or it is on? :P Basic tutorial, could help me in the future
22/10/2011, 12:52 AM   #3
Lorenc_
High-roller

Join Date: Jan 2010
Location: Australia
Posts: 4,174
Reputation: 983
Re: How to make a rotating camera on class selection

Quote:
 Originally Posted by ©•Riddy•© Looking good Lorenc, Gonna use it on BlackOps or it is on? :P Basic tutorial, could help me in the future
Yeah I might for 0.3d, basically rotating the player just to see how his player looks
Still have a lot to improve on that gamemode for 0.3d, hoping for it to be the most epic/realistic CoD server around (I would say yes in realism of the server between the actual blackops game)

Thanks for the comment Riddy

 22/10/2011, 02:55 AM #4 Xx_OutLawZ_xX Big Clucker   Join Date: Jul 2010 Posts: 97 Reputation: 12 Re: How to make a rotating camera on class selection Looks good
 22/10/2011, 07:04 AM #5 vassilis High-roller     Join Date: Nov 2009 Location: Greece,Athens Posts: 1,237 Reputation: 150 Re: How to make a rotating camera on class selection Hmm its good however you could explain better.Btw its good tutorial GG. __________________ Releases: The Renaissance 2 Project - Team Deathmatch[Changeable maps with timers|Adrenaline World Of Stunt®[IRC+JunkBuster ANTICHEAT+ZCMD+(+3000 OBJECTS)+SCREENS+LOT FEATURES]Scripting again Chaos Cops N Robbers for Unlimited Gaming Community | Greek SA-MP Community Vassilis.
 22/10/2011, 07:07 AM #6 Max_Coldheart Guest   Posts: n/a Re: How to make a rotating camera on class selection Looking good once again ! Good job.
 22/10/2011, 07:20 AM #7 SmiT Huge Clucker   Join Date: Oct 2011 Posts: 353 Reputation: 63 Re: How to make a rotating camera on class selection Nice one. Good job.
 22/10/2011, 08:00 AM #8 System64 Gangsta     Join Date: May 2011 Location: Zadar, Croatia Posts: 961 Reputation: 141 Re: How to make a rotating camera on class selection wow awesome, I was always wondering how to create something like this __________________ All my works I left SA:MP! Maybe once I start scripting again but now I'm based on web programming Soon, I'll buy domain system32.com.hr but for now you can contact me on LogoOff or on my Youtube channel!
 22/10/2011, 08:01 AM #9 Twizted High-roller     Join Date: Feb 2011 Posts: 1,480 Reputation: 219 Re: How to make a rotating camera on class selection Awesome work Lorenc. __________________ I'll never understand people like you. I hope one day you'll stop posting these shits. One day. And yeah, you don't look cool by doing these shits. You're just posting shit everywhere I see. So yeah, it's decreasing your reputation. You're turning a flame war everywhere on the forums and decreasing your well-made reputation amongst this community. Have fun trolling around, and flaming everybody, ungrateful being. I usually don't like to be rude, but people like you, urge me to do so.
22/10/2011, 10:33 AM   #10
Lorenc_
High-roller

Join Date: Jan 2010
Location: Australia
Posts: 4,174
Reputation: 983
Re: How to make a rotating camera on class selection

Quote:
 Originally Posted by vassilis Hmm its good however you could explain better.Btw its good tutorial GG.
IF YOU DON'T KNOW TRIGNOMETRY THEN READ THIS

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Ehab1911 Help Archive 1 14/06/2011 02:37 PM Admigo Help Archive 4 24/04/2011 01:49 PM TheKingWillem Help Archive 12 14/07/2010 10:32 PM Mikep. Help Archive 8 04/04/2010 09:56 PM laserhel50 Help Archive 3 17/12/2009 02:16 PM

All times are GMT. The time now is 04:17 AM.

 -- (DE) Deutsch -- (EN) English -- (ES) Español -- (FR) Français -- (NL) Dutch -- (RU) Русски Contact Us - SA-MP - Archive - Top