Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. Red Dead Redemption 2

      1. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
      4. Frontier Pursuits
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. Diamond Casino & Resort
      2. DLC
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA 6

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA IV Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA SA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA VC Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA III Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. News

    2. Forum Support

    3. Site Suggestions

jedijosh920

Rotating Camera?

Recommended Posts

jedijosh920

Does anyone have a rotating camera script where you use the controller or mouse to rotate around an entity? I know you have to use attach cam to entity multiple times with different offsets but that requires a lot of math :(

Share this post


Link to post
Share on other sites
MoMadenU

Is this what you had in mind? You would be feeding in the increment from the controller/mouse so you would not need to have a wait time. It's there just to demo the concept.

 

public void SpinAroundEntity()
{
var ped = Game.Player.Character;
var cam = World.CreateCamera(ped.Position,
Vector3.Zero, 60f);
cam.PointAt(ped);
float orbitAngle = 0;
float orbitIncrement = 0.5f;
int orbitWait = 10;
World.RenderingCamera = cam;
var endTime = Game.GameTime + 10000;
while (endTime > Game.GameTime)
{
if (orbitAngle >= 360)
orbitAngle = 0;
orbitAngle += orbitIncrement;
var nextCamLocation = RotateAround(ped.Position, 3.5f, orbitAngle);
World.RenderingCamera.Position = new Vector3(nextCamLocation.X, nextCamLocation.Y, ped.Position.Z);
Script.Wait(orbitWait);
}
World.DestroyAllCameras();
World.RenderingCamera = null;
}
public Vector2 RotateAround(Vector3 entityPosition, float radius, float orbitAngle)
{
float x = entityPosition.X + radius * (float)Math.Cos(orbitAngle * Math.PI / 180);
float y = entityPosition.Y - radius * (float)Math.Sin(orbitAngle * Math.PI / 180);
return new Vector2(x, y);
}

Share this post


Link to post
Share on other sites
jedijosh920

Thanks man, but what I had in mind was manually rotating the camera around an entity using the right stick on a controller or using a mouse.

Share this post


Link to post
Share on other sites
MoMadenU

For some reason I can't find the control code for left mouse move, but if you call this code below during OnTick (after creating the render cam), right mouse or right stick right will rotate the camera clockwise

around the entity. Entity can be anything since you only need to provide its position for RotateAround to work.

This is what you want, no?

 

 

private float _orbitAngle;
public void OnTickRotateChange()
{
if (World.RenderingCamera != null &&
(Game.IsControlPressed(2, Control.LookRightOnly) ||
Game.IsControlPressed(2, Control.WeaponWheelLeftRight)))
{
_orbitAngle += 1f;
if (_orbitAngle >= 360)
_orbitAngle = 0;
var ped = Game.Player.Character;
var nextCamLocation = RotateAround(ped.Position, 3.5f, _orbitAngle);
World.RenderingCamera.Position = new Vector3(nextCamLocation.X, nextCamLocation.Y, ped.Position.Z);
}
}

Share this post


Link to post
Share on other sites
jedijosh920

Yes this will do thanks! But what I wanted was a full 360 rotation, but if you can't do it, no worries, I don't want to hassle you. I can make do with this and I will credit you in my latest script that I'm making right now. Thanks again.

Share this post


Link to post
Share on other sites
MoMadenU

Yes this will do thanks! But what I wanted was a full 360 rotation, but if you can't do it, no worries, I don't want to hassle you. I can make do with this and I will credit you in my latest script that I'm making right now. Thanks again.

 

No hassles, I'm currently working on code to produce cinematic effects so specialized camera control is what I need as well. When you say full 360 rotation, do you mean just like gameplay camera?

I left Z axis fixed in my example but it can easily be added to the up/down control axis. This essentially gets you a full sphere which is technically better than the gameplay cam since gameplay locks a ground height.

 

There are no mouse left or up control codes I'm aware of so I'm going to need to add 2D direction detect to the code I already have that gets mouse X and Y screen coords.

Let me know if you want that since you are supporting both mouse and controller

Share this post


Link to post
Share on other sites
jedijosh920

Yeah, the gameplay camera is a good idea of what I want, full camera control rotating around an entity. I believe Rockstar uses a dragging mechanism with the mouse and just the right controller stick for controllers. And yes can I have the updated code? And would it also be possible to add a zooming function with the camera when you use the scroll wheel or move up or down on the left controller stick? Thanks a lot man for the help, appreciate it.

Share this post


Link to post
Share on other sites
Guad

Here's what I use for the Benny's Motorworks mod camera: http://pastebin.com/TvYXx9gy

You can ignore the lowrider specific parts and extract whatever you need.

Share this post


Link to post
Share on other sites
MoMadenU

Yeah, the gameplay camera is a good idea of what I want, full camera control rotating around an entity. I believe Rockstar uses a dragging mechanism with the mouse and just the right controller stick for controllers. And yes can I have the updated code? And would it also be possible to add a zooming function with the camera when you use the scroll wheel or move up or down on the left controller stick? Thanks a lot man for the help, appreciate it.

Here is my full Ubercam code http://pastebin.com/iUh9mcu6

 

I works like gameplay cam which is relative mouse move and not click drag move.

You can easily add left mouse click and equivalent controller control if you want it to function as grab and drag

 

I added mouse wheel, left stick to change radius.

Share this post


Link to post
Share on other sites
jedijosh920

Thank you, works as expected and what I wanted!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.