ikt Posted May 13, 2011 Share Posted May 13, 2011 (edited) 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 May 13, 2011 by ikt Link to comment Share on other sites More sharing options...
L0uNGeR Posted May 13, 2011 Share Posted May 13, 2011 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 More sharing options...
ikt Posted May 13, 2011 Author Share Posted May 13, 2011 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. Link to comment Share on other sites More sharing options...
Symbiote Posted May 13, 2011 Share Posted May 13, 2011 (edited) 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... Edited May 13, 2011 by AngryAmoeba Link to comment Share on other sites More sharing options...
L0uNGeR Posted May 13, 2011 Share Posted May 13, 2011 (edited) 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 May 13, 2011 by L0uNGeR Link to comment Share on other sites More sharing options...
Donny78 Posted May 14, 2011 Share Posted May 14, 2011 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 More sharing options...
ikt Posted May 14, 2011 Author Share Posted May 14, 2011 I think I almost get it. What does Vector3 do? Link to comment Share on other sites More sharing options...
lindsayslorach Posted May 14, 2011 Share Posted May 14, 2011 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 More sharing options...
L0uNGeR Posted May 14, 2011 Share Posted May 14, 2011 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now