function pointingAt(distance) {
const camera = mp.cameras.new("gameplay"); // gets the current gameplay camera
let position = camera.getCoord(); // grab the position of the gameplay camera as Vector3
let direction = camera.getDirection(); // get the forwarding vector of the direction you aim with the gameplay camera as Vector3
let farAway = new mp.Vector3((direction.x * distance) + (position.x), (direction.y * distance) + (position.y), (direction.z * distance) + (position.z)); // calculate a random point, drawn on a invisible line between camera position and direction (* distance)
let result = mp.raycasting.testPointToPoint(position, farAway, null, 17); // now test point to point - intersects with map and objects [1 + 16]
return result; // and return the result ( undefined, if no hit )
}
Да вот проблема, через raycast можно, да. Но вот куда конкретно луч пускать не ясно. У cam.GetRotation() очень странные выходные данные, почему-то. Так что не получилось у меня сделать используя поворот камеры..Направление куда смотрит камера = heading. Позицию в мире(куда именно смотрит прицел) - можно определить через raycasting. Этот принцип подходит для любого 3д мира, в рейдже есть нативки для использования рейкастов
На c# у камеры нет метода getDirection, только getRotation, в этом и проблема. А как я уже объяснил выше, через rotation сделать не получилось. Мб я слишком туп , не понятно крч.JavaScript:function pointingAt(distance) { const camera = mp.cameras.new("gameplay"); // gets the current gameplay camera let position = camera.getCoord(); // grab the position of the gameplay camera as Vector3 let direction = camera.getDirection(); // get the forwarding vector of the direction you aim with the gameplay camera as Vector3 let farAway = new mp.Vector3((direction.x * distance) + (position.x), (direction.y * distance) + (position.y), (direction.z * distance) + (position.z)); // calculate a random point, drawn on a invisible line between camera position and direction (* distance) let result = mp.raycasting.testPointToPoint(position, farAway, null, 17); // now test point to point - intersects with map and objects [1 + 16] return result; // and return the result ( undefined, if no hit ) }
Источник
using RAGE;
using System;
namespace HardLife.Utils
{
internal static class Direction
{
internal static Vector3 GetDirection(Vector3 camCoord, Vector3 camRot, float distance = 10.3f)
{
Vector3 lengthVector = multiply(rot_to_direction(camRot), distance);
Vector3 posLookAt = add(camCoord, lengthVector);
return posLookAt;
}
private static Vector3 multiply(Vector3 vector, float x)
{
Vector3 result = new Vector3(vector.X, vector.Y, vector.Z);
result.X *= x;
result.Y *= x;
result.Z *= x;
return result;
}
private static Vector3 add(Vector3 vectorA, Vector3 vectorB)
{
Vector3 result = new Vector3(vectorA.X, vectorA.Y, vectorA.Z);
result.X += vectorB.X;
result.Y += vectorB.Y;
result.Z += vectorB.Z;
return result;
}
private static Vector3 rot_to_direction(Vector3 rot)
{
float radiansZ = rot.Z * 0.0174532924f;
float radiansX = rot.X * 0.0174532924f;
float num = MathF.Abs((float)MathF.Cos((float)radiansX));
Vector3 dir = new Vector3();
dir.X = (float)((float)((float)(-(float)MathF.Sin((float)radiansZ))) * (float)num);
dir.Y = (float)((float)((float)MathF.Cos((float)radiansZ)) * (float)num);
dir.Z = (float)MathF.Sin((float)radiansX);
return dir;
}
}
}
Я свечку за тебя поставил в церкви, спасибоC#:using RAGE; using System; namespace HardLife.Utils { internal static class Direction { internal static Vector3 GetDirection(Vector3 camCoord, Vector3 camRot, float distance = 10.3f) { Vector3 lengthVector = multiply(rot_to_direction(camRot), distance); Vector3 posLookAt = add(camCoord, lengthVector); return posLookAt; } private static Vector3 multiply(Vector3 vector, float x) { Vector3 result = new Vector3(vector.X, vector.Y, vector.Z); result.X *= x; result.Y *= x; result.Z *= x; return result; } private static Vector3 add(Vector3 vectorA, Vector3 vectorB) { Vector3 result = new Vector3(vectorA.X, vectorA.Y, vectorA.Z); result.X += vectorB.X; result.Y += vectorB.Y; result.Z += vectorB.Z; return result; } private static Vector3 rot_to_direction(Vector3 rot) { float radiansZ = rot.Z * 0.0174532924f; float radiansX = rot.X * 0.0174532924f; float num = MathF.Abs((float)MathF.Cos((float)radiansX)); Vector3 dir = new Vector3(); dir.X = (float)((float)((float)(-(float)MathF.Sin((float)radiansZ))) * (float)num); dir.Y = (float)((float)((float)MathF.Cos((float)radiansZ)) * (float)num); dir.Z = (float)MathF.Sin((float)radiansX); return dir; } } }