Formula to create an object directly under a player, flat
#1

What would the co-ordinates be to create an object underneath a player, flat, no matter where they're standing? So on a hill, angle etc

I'm not good at maths and the formula would be highly appreciated, thanks in advance!
Reply
#2

You can use MapAndreas.
http://forum.sa-mp.com/showpost.php?...&postcount=153
Reply
#3

Try with ColAndreas with this line maybe

CA_RayCastLineAngle (Float:StartX, Float:StartY, Float:StartZ, Float:EndX, Float:EndY, Float:EndZ, &Float, &Float:y, &Float:z, &Float:rx, &Float:ry, &Float:rz)

Quote:

StartX,StartY,StartZ Start position of ray cast.
EndX,EndY,EndZ Endposition of ray cast.
&x,&y,&z Collision position is stored in these references.
&rx,&ry,&rz Rotation of surface of collision.

Reply
#4

Directly under a player? I believe sa-mp's skin heights are all(or almost all) the same being 1.8 or 2.0, so you could get the player'pos and just create an object 0.9-1.0 below the z you get, and it will be directly under him, however if you want to create the object on the land/object under him, you need to either use MapAndreas or ColAndreas(recommended).
Reply
#5

Quote:
Originally Posted by PrO.GameR
Посмотреть сообщение
Directly under a player? I believe sa-mp's skin heights are all(or almost all) the same being 1.8 or 2.0, so you could get the player'pos and just create an object 0.9-1.0 below the z you get, and it will be directly under him, however if you want to create the object on the land/object under him, you need to either use MapAndreas or ColAndreas(recommended).
Yeah it's just the angle that I need to formulate, z-1 pretty much creates it directly under him, then the rotation angle.

MapAndreas didn't quiet do it:


Did I use it right?
pawn Код:
new Float: x, Float: y, Float: z, Float:a;
    GetPlayerFacingAngle(playerid, a);
    GetPlayerPos(playerid, x, y, z);
    MapAndreas_FindZ_For2DCoord(x, y, z);
Reply
#6

Yeah but sadly MapAndreas won't provide the rotation, you could create some function to do it for you (checking Z of the area around yours, providing an aproximate angle), but it's like reinventing the wheel so just use ColAndreas for that matter.
Reply
#7

Yeah you need ColAndreas it will give you the surface angle but you still need to figure out offsets. Once you have your angles you can rotate the object on the z-axis and still maintain the correct angle with this function.

Код:
stock ObjectRotateZ(Float:RX, Float:RY, Float:RZ, Float:rot_z, &Float:NewRX, &Float:NewRY, &Float:NewRZ)
{
	new
		Float:sinx,
		Float:siny,
		Float:sinz,
		Float:cosx,
		Float:cosy,
		Float:cosz;

    FloatConvertValue(RX, RY, RZ, sinx, siny, sinz, cosx, cosy, cosz);
    // Convert from one euler angle sequence (ZXY) to another and add the rotation
    FloatConvertValue(asin(cosx * cosy), atan2(sinx, cosx * siny) + rot_z, atan2(cosy * cosz * sinx - siny * sinz, cosz * siny - cosy * sinx * -sinz),
		sinx, siny, sinz, cosx, cosy, cosz);

    // Convert back to the original euler angle sequence and apply the new rotation to the object
    NewRX = asin(cosx * siny),
	NewRY = atan2(cosx * cosy, sinx),
	NewRZ = atan2(cosz * sinx * siny - cosy * sinz, cosy * cosz + sinx * siny * sinz);
    return 1;
}

stock FloatConvertValue(Float:rot_x, Float:rot_y, Float:rot_z, &Float:sinx, &Float:siny, &Float:sinz, &Float:cosx, &Float:cosy, &Float:cosz)
{
    sinx = floatsin(rot_x, degrees);
    siny = floatsin(rot_y, degrees);
    sinz = floatsin(rot_z, degrees);
    cosx = floatcos(rot_x, degrees);
    cosy = floatcos(rot_y, degrees);
    cosz = floatcos(rot_z, degrees);
    return 1;
}
Reply
#8

Quote:
Originally Posted by Pottus
Посмотреть сообщение
Yeah you need ColAndreas it will give you the surface angle but you still need to figure out offsets. Once you have your angles you can rotate the object on the z-axis and still maintain the correct angle with this function.

Код:
stock ObjectRotateZ(Float:RX, Float:RY, Float:RZ, Float:rot_z, &Float:NewRX, &Float:NewRY, &Float:NewRZ)
{
	new
		Float:sinx,
		Float:siny,
		Float:sinz,
		Float:cosx,
		Float:cosy,
		Float:cosz;

    FloatConvertValue(RX, RY, RZ, sinx, siny, sinz, cosx, cosy, cosz);
    // Convert from one euler angle sequence (ZXY) to another and add the rotation
    FloatConvertValue(asin(cosx * cosy), atan2(sinx, cosx * siny) + rot_z, atan2(cosy * cosz * sinx - siny * sinz, cosz * siny - cosy * sinx * -sinz),
		sinx, siny, sinz, cosx, cosy, cosz);

    // Convert back to the original euler angle sequence and apply the new rotation to the object
    NewRX = asin(cosx * siny),
	NewRY = atan2(cosx * cosy, sinx),
	NewRZ = atan2(cosz * sinx * siny - cosy * sinz, cosy * cosz + sinx * siny * sinz);
    return 1;
}

stock FloatConvertValue(Float:rot_x, Float:rot_y, Float:rot_z, &Float:sinx, &Float:siny, &Float:sinz, &Float:cosx, &Float:cosy, &Float:cosz)
{
    sinx = floatsin(rot_x, degrees);
    siny = floatsin(rot_y, degrees);
    sinz = floatsin(rot_z, degrees);
    cosx = floatcos(rot_x, degrees);
    cosy = floatcos(rot_y, degrees);
    cosz = floatcos(rot_z, degrees);
    return 1;
}
I still don't understand in what way I would use what functions/calls to set the objects rotational position/offset
Reply
#9

This is what I understood from Pottus's post:

Get offsets of each weapon ready so it sits perfectly on a 0,0,0 angle object
Get ground Z angle
feed them both to this function, get new offsets for wherever you want to drop
PHP код:
ObjectRotateZ(Float:RXFloat:RYFloat:RZFloat:rot_z, &Float:NewRX, &Float:NewRY, &Float:NewRZ
create object there
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)