Hello, I’m writing an aim assist script. I usally write my scripts in Lua but C# has much more advanced math features. I have my own custom script handling the Matrix’s and all the math for them. I checked all my code and everything seems right on the math side of things. Can someone point me in the right direction. Thanks
using CitizenFX.Core;
using CustomMath;
using System;
using static CitizenFX.Core.Native.API;
namespace AimAssist
{
public class AimAssist : BaseScript
{
public AimAssist()
{
EventHandlers["onClientResourceStart"] += new Action<string>(OnClientResourceStart);
}
private void AimLoop()
{
while (true)
{
Vector3 Source = GetFinalRenderedCamCoord();
Vector3 Player = GetEntityCoords(PlayerPedId(), true);
Ped ClosestPed = World.GetClosest<Ped>(new Vector2(Player.X, Player.Y));
Vector3 Target = GetPedBoneCoords(ClosestPed.Handle, 0x796E, 0f, 0f, 0f);
Matrix4x4 matrix = Matrix4x4.CreateLookAt(Source, Target);
float yaw = (float)Math.Atan2(matrix.V13, matrix.V33);
float pitch = (float)Math.Asin(-matrix.V23);
float roll = (float)Math.Atan2(matrix.V21, matrix.V22);
Chat("Roll: " + roll + " Pitch: " + pitch + " Yaw: " + yaw);
SetGameplayCamRelativeRotation(roll, pitch, yaw);
Wait(1);
}
}
private void Chat(string message)
{
TriggerEvent("chat:addMessage", new
{
color = new[] { 255, 0, 0 },
args = new[] { "[AimAssist]", $"[LOG] " + message }
});
}
private void OnClientResourceStart(string resourceName)
{
if (GetCurrentResourceName() != resourceName) return;
RegisterCommand("aimassist", new Action(() =>
{
AimLoop();
}), false);
}
}
}