Random coordinates around a positions
#1

Hey

How i can get random positions around a position?

For example: Player standing at the middle of the circle


How i can get positions outside of the circle within a given range? And could you show an example too please?
Reply
#2

Get the centre of the circle and then use 2 randoms to add to the X and Y, i.e.

PHP код:

new Float:CentreCircle[3];

CentreCircle[0] = 0;
CentreCircle[1] = 0;
CentreCircle[2] = 0;

new 
randX random(/*Max*/ /*Min*/)+/*Min*/,
       
randY random(/*Max*/ /*Min*/)+/*Min*/;

printf("Random Position: X: %f, Y: %f, Z: %f"CentreCircle[0]+randXCentreCircle[1]+randYCentreCircle[2]); 
Not tested but pretty sure this something like this work.
Reply
#3

Quote:
Originally Posted by ItsRobinson
Посмотреть сообщение
Not tested but pretty sure this something like this work.
No, that's incorrect, follow some math courses ...

This is correct:
Код:
//A function to get a point on the edge of a circle, given a radius and an angle
GetPointOnEdgeOfCircle(&Float:x, &Float:y, Float:r, Float:a, bool:isGTAAngle = false) {
	if(isGTAAngle) { //In case the angle was retrieved with GetPlayerFacingAngle, GetVehicleZAngle, ...
		a += 90.0;
	}
	x += r * floatcos(a, degrees);
	y += r * floatsin(a, degrees);
}

//Get the player's position
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);

//Example with radius = 50.0
GetPointOnEdgeOfCircle(x, y, 50.0, frandom(360.0)); //See this post for frandom
Reply
#4

Quote:
Originally Posted by Freaksken
Посмотреть сообщение
No, that's incorrect, follow some math courses ...

This is correct:
Код:
//A function to get a point on the edge of a circle, given a radius and an angle
GetPointOnEdgeOfCircle(&Float:x, &Float:y, Float:r, Float:a, bool:isGTAAngle = false) {
	if(isGTAAngle) { //In case the angle was retrieved with GetPlayerFacingAngle, GetVehicleZAngle, ...
		a += 90.0;
	}
	x += r * floatcos(a, degrees);
	y += r * floatsin(a, degrees);
}

//Get the player's position
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);

//Example with radius = 50.0
GetPointOnEdgeOfCircle(x, y, 50.0, frandom(360.0)); //See this post for frandom
I mean, mine would work, just yours has radius's
Reply
#5

Quote:
Originally Posted by ItsRobinson
Посмотреть сообщение
I mean, mine would work, just yours has radius's
You clearly don't know your math.
Reply
#6

Quote:
Originally Posted by Freaksken
Посмотреть сообщение
No, that's incorrect, follow some math courses ...

This is correct:
Код:
//A function to get a point on the edge of a circle, given a radius and an angle
GetPointOnEdgeOfCircle(&Float:x, &Float:y, Float:r, Float:a, bool:isGTAAngle = false) {
	if(isGTAAngle) { //In case the angle was retrieved with GetPlayerFacingAngle, GetVehicleZAngle, ...
		a += 90.0;
	}
	x += r * floatcos(a, degrees);
	y += r * floatsin(a, degrees);
}

//Get the player's position
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);

//Example with radius = 50.0
GetPointOnEdgeOfCircle(x, y, 50.0, frandom(360.0)); //See this post for frandom
Thanks, but it not works as i wanted.
I'm making a 'dumpster diving' system (you can pick up up trashes from the dumpsters and drop it around the player). That i made is almost working as i want, but there is a bug whenever the object hit the player which cause collapse damage (about 3-25 points) for the player.
How i should make this system to place the object around the player like this?
Reply
#7

bump
Reply
#8

Please show your code so we can understand more
Reply
#9

Код:
new Float:X, Float:Y, Float:Z;
new objectid = CreateTimedObject(RandomEx(60000, 80000), 1264, DumpsterData[dumpsterid][dumpsterX], DumpsterData[dumpsterid][dumpsterY], (DumpsterData[dumpsterid][dumpsterZ] + 1.20), 0.0, 0.0, random(360));

switch(DumpsterData[dumpsterid][dumpsterSide])
{
	case true: // Left
	{
		GetPointInFront2D(DumpsterData[dumpsterid][dumpsterActionX], DumpsterData[dumpsterid][dumpsterActionY], ((DumpsterData[dumpsterid][dumpsterR] + (RandomFloat(40.0, 50.0))) + 180.0), RandomFloat(1.75, 2.90), X, Y);
	}
	case false: // Right
	{
		GetPointInFront2D(DumpsterData[dumpsterid][dumpsterActionX], DumpsterData[dumpsterid][dumpsterActionY], ((DumpsterData[dumpsterid][dumpsterR] + (RandomFloat(-40.0, -50.0))) + 180.0), RandomFloat(1.75, 2.90), X, Y);
	}
}

GetPlayerPos(playerid, Z, Z, Z);					
MoveDynamicObject(objectid, X, Y , (Z - 0.50), 9.0);
I want to make it to drop around the player OR drop before / next / behind the player but the object do not hit the player
Reply
#10

What radius do you use? If the object hits you, the radius is not big enough.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)