Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      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. Grand Theft Auto Series

      1. Bugs*
      2. 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. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. 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. Red Dead Redemption 2

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

    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

    2. Support

    3. Suggestions

Programming and maths


ikt
 Share

Recommended Posts

Seems I can't do maths. I have problems with getting things around the player. It IS possible, with Scripthook, because others have done it.

 

Now this is the first problem:

I have two coordinates, one of the player and one of something (a car) that needs to be launched into the direction the character (or camera) is facing. I can't do that and I can't seem to think of any method to achieve that. I use 'AddForceToxxx' to launch stuff, and cars always seem to launch in the wrong direction.

 

Second problem:

Now I have the player coordinates and I want to get a circle around that player. On that circle I want to have a point which the character is facing.

 

In short, I want add another effect to the gun nozzle. But I can't find its position, so I'll use this.

 

For rotation, I'm using the camera angle, but might there be another way?

Edited by ikt
Link to comment
Share on other sites

 

Seems I can't do maths. I have problems with getting things around the player. It IS possible, with Scripthook, because others have done it.

Of course it's possible, it's C++, the most extreme math can be done in this language.

All you need is #include <math.h> and maybe #define _USE_MATH_DEFINES, then you can use it, like this cos() function here

 

for(int n = 1; n <= nodes; n++) {   f32 tmpX = x + radius * cos(2 * M_PI * n / nodes);   //etc......

 

 

 

Now this is the first problem:

I have two coordinates, one of the player and one of something (a car) that needs to be launched into the direction the character (or camera) is facing. I can't do that and I can't seem to think of any method to achieve that. I use 'AddForceToxxx' to launch stuff, and cars always seem to launch in the wrong direction.

I'm pretty sure it has been said before, but you should use "ApplyForce". This is was I have in some old script of mine:

 

// Smash-Roll sidewaysApplyForceToCar(v, 3, 30.0, 0.0, 0.0, 0.0, 0.0, 20.0, 0, 1, 1, 1);

 

 

 

Second problem:

Now I have the player coordinates and I want to get a circle around that player. On that circle I want to have a point which the character is facing.

 

In short, I want add another effect to the gun nozzle. But I can't find its position, so I'll use this.

 

For rotation, I'm using the camera angle, but might there be another way?

The cos() part above is actually part of a function I made to get a circle of explosions around a player, but it's not that useful IMHO.

I already replied to your post in the ScriptHook topic and told you about Around() in C#, I don't know if C++ ScriptHook has such a feature.

 

Link to comment
Share on other sites

Thanks! Didn't know I could use math.h in this. I'll give it a shot. I also suck pretty much at math and examples online with advanced maths combined into a programming language makes me wtf. Something with cosinus etc should work indeed.

 

This has been keeping me out of my sleep for days and I need to do regular math homeworks (which I didn't understand before) to get my mind relaxed again. tounge.gif

Link to comment
Share on other sites

I don't know if this is really dumb and unnecessary, but... here's how I made a circle around the player in C# for my Weapon Weight script, using a rotation algorithm I found on Wikipedia:

 

 

// Angle of each rotation, and sine/cosine of the angledouble rotateAngle = Helper.DegreeToRadian(20.0F),       angleSine = Math.Sin(rotateAngle),       angleCosine = Math.Cos(rotateAngle);// How many rotations are needed to make a circleint numOfRotations = (360 / (int)Helper.RadianToDegree(rotateAngle));// A point on the circle (circle radius is 1.25F)Vector3 relOffset = new Vector3(0.0F, 1.25F, 0.0F);// Working values for rotation around playerfloat x, y;// Rotate the relative offset (relOffset) on a circle around playerfor (int i = 1; i <= numOfRotations; i++) {   x = relOffset.X;   y = relOffset.Y;   relOffset.X = (float)((x * angleCosine) - (y * angleSine)); // ROTATION   relOffset.Y = (float)((x * angleSine) + (y * angleCosine)); // MATHS D:   // Then you can use the relOffset vector to get points around the player, Player.Character.GetOffsetPosition(relOffset)   // Together, all the points make a circle.}

 

 

Edit: I had to clean up the code a lot to make it a little more readable... whatsthat.gif

Edited by AngryAmoeba
Link to comment
Share on other sites

Nice, I actually have a similar function (if not the same).

I'm not that good with math, so I told my brother (who does university in physics) I wanted to get a circle around the player by using "nodes".

He would do the math, I would do the programming...

 

Here's what I used in C++ 2 years ago in GTA IV 1.0.1.0

 

for(int n = 1; n <= nodes; n++){   f32 tmpX = x + radius * cos(2 * M_PI * n / nodes);   f32 tmpY = y + radius * sin(2 * M_PI * n / nodes);}

 

 

Today I use this in C#

 

private Vector3 CalculateCircleNodePosition(Vector3 center, int node, int nodeCount, float radius){   float x, y;   x = (float)(center.X + radius * Math.Cos(2 * Math.PI * node / nodeCount));   y = (float)(center.Y + radius * Math.Sin(2 * Math.PI * node / nodeCount));   return new Vector3(x, y, center.Z);}// Then use like this:   for (node = 1; node <= nodeCount; node++)   {       nodePos = CalculateCircleNodePosition(center, node, nodeCount, radius);       // Do something on that node (add an explosion, spawn a ped, etc...   }

 

Edited by L0uNGeR
Link to comment
Share on other sites

 

pos + dir * distance

 

 

That's the basic formula IIRC for the point from the camera (aiming position).

 

So like C#:

 

 

float    x = Game.CurrentCamera.Position.X + Game.CurrentCamera.Direction.X * 10f,   y = Game.CurrentCamera.Position.Y + Game.CurrentCamera.Direction.Y * 10f,   z = Game.CurrentCamera.Position.Z + Game.CurrentCamera.Direction.Z * 10f;Vector3 AimPos = new Vector3(x, y, z);

 

 

That will give you a point 10 units away from the camera on the line (in 3D space) it's aiming down.

Link to comment
Share on other sites

lindsayslorach

A Vector3 is used to hold positions and rotations of things in 3d space, using X, Y and Z values, 3 floats.

Link to comment
Share on other sites

I think I almost get it. What does Vector3 do?

It just holds 3 float values (X Y Z), for use in 3D measuring.

 

 

Describes and manipulates a vector in three-dimensional (3-D) space.
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.