Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[HELP]Math required for a 3D game aimbot

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Thunder_Bird
Cheater
Reputation: 0

Joined: 27 Apr 2018
Posts: 33
Location: pakistan

PostPosted: Sat Jul 20, 2019 7:31 pm    Post subject: [HELP]Math required for a 3D game aimbot Reply with quote

I'm trying to make aimbot but I already failed in maths and trigonometry sux and all math sux but I want to make aimbot so I will be great-full to anyone who will help me with maths

I have my XYZ coords, Enemy XYZ coords, and camera XY angle(eye position what we call it probably)

I just want to know how can I calculate accurate camera XY angle to write at

im writing it in LUA
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Sun Jul 21, 2019 9:32 am    Post subject: Reply with quote

My maths also sux, but maybe something like this:

Code:
-- Calculate distance
function distance(chicken,you)
 return math.sqrt( (chicken.x - you.x) ^2 )
end

-- Camera Angle
function angleTo2DVec(startX, startY, angle, distance)
   angle = angle * (math.pi/180)
   return startX + math.cos(angle)*distance, startY + math.sin(angle)*distance
end

--testing values
local x, y = 100, 300
local angle = 45
local distance = 300

local newX, newY = angleTo2DVec(x, y, angle, distance)
print(newX, newY)


or use math.atan2

Code:
-- Angle between 2 points
local angle = math.atan2 ( centre.y - target.y, target.x - centre.x)
-- OR
local angle = -math.atan2 ( target.y - centre.y, target.x - centre.x)

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Thunder_Bird
Cheater
Reputation: 0

Joined: 27 Apr 2018
Posts: 33
Location: pakistan

PostPosted: Sun Jul 21, 2019 11:14 am    Post subject: Reply with quote

Corroder wrote:
My maths also sux, but maybe something like this:

Code:
-- Calculate distance
function distance(chicken,you)
 return math.sqrt( (chicken.x - you.x) ^2 )
end

-- Camera Angle
function angleTo2DVec(startX, startY, angle, distance)
   angle = angle * (math.pi/180)
   return startX + math.cos(angle)*distance, startY + math.sin(angle)*distance
end

--testing values
local x, y = 100, 300
local angle = 45
local distance = 300

local newX, newY = angleTo2DVec(x, y, angle, distance)
print(newX, newY)


or use math.atan2

Code:
-- Angle between 2 points
local angle = math.atan2 ( centre.y - target.y, target.x - centre.x)
-- OR
local angle = -math.atan2 ( target.y - centre.y, target.x - centre.x)
I really appreciate this brother and would like to ask few more things,
1. you only used X axis to calculate distance between two 3d object, why did you ignore y and z axis? is it not necessary for aimbot?
2. in function angle2dvec you passed 4 variables, x,y,angle,distance, where x and y are my camera x and y angles(I think so) and the distance is what we calculated above right? but what does that angle means? how to get/calculate it?
If you feel so please explain further and few things I would like to mention is that im making this aimbot for gta vice city, and all values are float type.
3. about this
Code:
-- Angle between 2 points
local angle = math.atan2 ( centre.y - target.y, target.x - centre.x)
-- OR
local angle = -math.atan2 ( target.y - centre.y, target.x - centre.x)

how can I find the center x an y? by dividing distance by 2?
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1535

PostPosted: Sun Jul 21, 2019 1:37 pm    Post subject: Reply with quote

Check out a completed Project.

https://forum.cheatengine.org/viewtopic.php?p=5737028&sid=6e6cdf33970cbb50e5d191ab1a86ffee

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sun Jul 21, 2019 6:22 pm    Post subject: Reply with quote

Here are a few helper funcs I wrote for some stuff of mine. Distance and degree/radian related:

Code:

----------------------------------------------------------------------------------------------------
-- func: math.distance2d
-- desc: Returns the 2D distance between two sets of coords.
----------------------------------------------------------------------------------------------------
function math.distance2d(x1, y1, x2, y2)
    local x = x2 - x1;
    local y = y2 - y1;
    return math.sqrt((x * x) + (y * y));
end

----------------------------------------------------------------------------------------------------
-- func: math.distance3d
-- desc: Returns the 3D distance between two sets of coords.
----------------------------------------------------------------------------------------------------
function math.distance3d(x1, y1, z1, x2, y2, z2)
    local x = x2 - x1;
    local y = y2 - y1;
    local z = z2 - z1;
    return math.sqrt((x * x) + (y * y) + (z * z));
end

----------------------------------------------------------------------------------------------------
-- func: math.degree2rad
-- desc: Converts a degree to a radian.
----------------------------------------------------------------------------------------------------
function math.degree2rad(d)
    local pi = 3.14159265359;
    return d * (pi / 180);
end

----------------------------------------------------------------------------------------------------
-- func: math.rad2degree
-- desc: Converts a radian to a degree.
----------------------------------------------------------------------------------------------------
function math.rad2degree(r)
    local pi = 3.14159265359;
    return r * (180 / pi);
end

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Sun Jul 21, 2019 7:14 pm    Post subject: Reply with quote

Quote:
I really appreciate this brother and would like to ask few more things,
1. you only used X axis to calculate distance between two 3d object, why did you ignore y and z axis? is it not necessary for aimbot?
2. in function angle2dvec you passed 4 variables, x,y,angle,distance, where x and y are my camera x and y angles(I think so) and the distance is what we calculated above right? but what does that angle means? how to get/calculate it?
If you feel so please explain further and few things I would like to mention is that im making this aimbot for gta vice city, and all values are float type.
3. about this


A1:
X, for the distance, means not as X-axis. That means as the centre of the objects.
Z-axis need for flying objects or top-bottom view.

A2:
Calculate angle measures example:

distance A to B (AB = hypotenuse side) = 8
distance A to C (AC = adjacent side) = 6
the measure of angle A ?.

cos(A)​=AB/AC
cos(A)=6/8
angle A = cos^-1 x [6 / 8]
angle A = 41.41 degree


Calculate Angle Between Source Object (You) And Destination Object (Chicken):

Code:
function angleBetween ( srcObj, dstObj )
  local xDist = dstObj.x-srcObj.x ;
  local yDist = dstObj.y-srcObj.y
  local angleBetween = math.deg( math.atan( yDist/xDist ) )
     if ( srcObj.x < dstObj.x ) then
         angleBetween = angleBetween+90
     else
        angleBetween = angleBetween-90
    end
  return angleBetween
end



A3:
Finding the centre of 2D object and calc the distance, for example:

Code:
f = createForm()

you = createPanel(f)
you.setSize(20,20)
you.setPosition(30,40)  --left,top

chicken = createPanel(f)
chicken.setSize(20,20)
chicken.setPosition(80,90)  --left,top


---- ======= #1 Method

function distance_getDiff(x1,y1,w1,h1, x2,y2,w2,h2)
 return x2 - x1 - w1, y2 - y1 - h1, w1 + w2, h1 + h2
end

youX, youY, youW, youH = 30, 40, 20, 20
chickenX, chickenY, chickenW, chickenH = 80, 90, 20, 20
distanceBetweenYouAndChicken = distance_getDiff(youX, youY, youW, youH, chickenX, chickenY, chickenW, chickenH)
print(distanceBetweenYouAndChicken) -- = 30


---- ======= #2 Method

-- Get centre point of objects
H_centreYou = math.floor(you.width/2)
V_centreYou = math.floor(you.height/2)
centreYou = math.floor((H_centreYou + V_centreYou) /2)
print(centreYou)  -- = 10

H_centreChicken = math.floor(chicken.width/2)
V_centreChicken = math.floor(chicken.height/2)
centreChicken = math.floor((H_centreChicken + V_centreChicken) /2)
print(centreChicken)  -- = 10

-- Calc distance between 2 objects point to centre object
distanceBetweenChickenAndYou = math.sqrt( (centreChicken - centreYou)^2 )
print(distanceBetweenYouAndChicken)  -- = 30



Anyhow, atom0s have you better solutions. And just remember as I said, my math is sux. Rolling Eyes

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Thunder_Bird
Cheater
Reputation: 0

Joined: 27 Apr 2018
Posts: 33
Location: pakistan

PostPosted: Mon Jul 22, 2019 12:59 am    Post subject: Reply with quote

atom0s wrote:
Here are a few helper funcs I wrote for some stuff of mine. Distance and degree/radian related:

Code:

----------------------------------------------------------------------------------------------------
-- func: math.distance2d
-- desc: Returns the 2D distance between two sets of coords.
----------------------------------------------------------------------------------------------------
function math.distance2d(x1, y1, x2, y2)
    local x = x2 - x1;
    local y = y2 - y1;
    return math.sqrt((x * x) + (y * y));
end

----------------------------------------------------------------------------------------------------
-- func: math.distance3d
-- desc: Returns the 3D distance between two sets of coords.
----------------------------------------------------------------------------------------------------
function math.distance3d(x1, y1, z1, x2, y2, z2)
    local x = x2 - x1;
    local y = y2 - y1;
    local z = z2 - z1;
    return math.sqrt((x * x) + (y * y) + (z * z));
end

----------------------------------------------------------------------------------------------------
-- func: math.degree2rad
-- desc: Converts a degree to a radian.
----------------------------------------------------------------------------------------------------
function math.degree2rad(d)
    local pi = 3.14159265359;
    return d * (pi / 180);
end

----------------------------------------------------------------------------------------------------
-- func: math.rad2degree
-- desc: Converts a radian to a degree.
----------------------------------------------------------------------------------------------------
function math.rad2degree(r)
    local pi = 3.14159265359;
    return r * (180 / pi);
end

Thanks dude this is really helpful

Corroder wrote:
Quote:
I really appreciate this brother and would like to ask few more things,
1. you only used X axis to calculate distance between two 3d object, why did you ignore y and z axis? is it not necessary for aimbot?
2. in function angle2dvec you passed 4 variables, x,y,angle,distance, where x and y are my camera x and y angles(I think so) and the distance is what we calculated above right? but what does that angle means? how to get/calculate it?
If you feel so please explain further and few things I would like to mention is that im making this aimbot for gta vice city, and all values are float type.
3. about this


A1:
X, for the distance, means not as X-axis. That means as the centre of the objects.
Z-axis need for flying objects or top-bottom view.

A2:
Calculate angle measures example:

distance A to B (AB = hypotenuse side) = 8
distance A to C (AC = adjacent side) = 6
the measure of angle A ?.

cos(A)​=AB/AC
cos(A)=6/8
angle A = cos^-1 x [6 / 8]
angle A = 41.41 degree


Calculate Angle Between Source Object (You) And Destination Object (Chicken):

Code:
function angleBetween ( srcObj, dstObj )
  local xDist = dstObj.x-srcObj.x ;
  local yDist = dstObj.y-srcObj.y
  local angleBetween = math.deg( math.atan( yDist/xDist ) )
     if ( srcObj.x < dstObj.x ) then
         angleBetween = angleBetween+90
     else
        angleBetween = angleBetween-90
    end
  return angleBetween
end



A3:
Finding the centre of 2D object and calc the distance, for example:

Code:
f = createForm()

you = createPanel(f)
you.setSize(20,20)
you.setPosition(30,40)  --left,top

chicken = createPanel(f)
chicken.setSize(20,20)
chicken.setPosition(80,90)  --left,top


---- ======= #1 Method

function distance_getDiff(x1,y1,w1,h1, x2,y2,w2,h2)
 return x2 - x1 - w1, y2 - y1 - h1, w1 + w2, h1 + h2
end

youX, youY, youW, youH = 30, 40, 20, 20
chickenX, chickenY, chickenW, chickenH = 80, 90, 20, 20
distanceBetweenYouAndChicken = distance_getDiff(youX, youY, youW, youH, chickenX, chickenY, chickenW, chickenH)
print(distanceBetweenYouAndChicken) -- = 30


---- ======= #2 Method

-- Get centre point of objects
H_centreYou = math.floor(you.width/2)
V_centreYou = math.floor(you.height/2)
centreYou = math.floor((H_centreYou + V_centreYou) /2)
print(centreYou)  -- = 10

H_centreChicken = math.floor(chicken.width/2)
V_centreChicken = math.floor(chicken.height/2)
centreChicken = math.floor((H_centreChicken + V_centreChicken) /2)
print(centreChicken)  -- = 10

-- Calc distance between 2 objects point to centre object
distanceBetweenChickenAndYou = math.sqrt( (centreChicken - centreYou)^2 )
print(distanceBetweenYouAndChicken)  -- = 30



Anyhow, atom0s have you better solutions. And just remember as I said, my math is sux. Rolling Eyes

Answer 3 started to scaring me, im going to try these things you mentioned


1 more thing, does the data type matters? I mean all the values I have are in float, does this effect the calculation in any way?
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Mon Jul 22, 2019 1:07 am    Post subject: Reply with quote

Thunder_Bird wrote:

1 more thing, does the data type matters? I mean all the values I have are in float, does this effect the calculation in any way?


I think the data store in the game as floating values.
Please, read the code from the link provided by Aylin.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites