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

    1. GTANet.com

    1. GTA Online

      1. Los Santos Tuners
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. Grand Theft Auto Series

      1. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
    6. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
    7. GTA III

      1. Guides & Strategies
      2. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

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

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

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

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

      1. GTANet 20th Anniversary
    2. Support

    3. Suggestions

Rotating Camera?


jedijosh920
 Share

Recommended Posts

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 :(

Link to comment
Share on other sites

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);
}
  • Like 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);
}
}
  • Like 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 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.