+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: How to know/predict if an object will hit me or not?

  1. #1
    Wire Amateur napalmstrike2007's Avatar
    Join Date
    Feb 2010
    Posts
    43
    Blog Entries
    1

    Default How to know/predict if an object will hit me or not?

    Hello there dear wiremod community, I have an important problem.
    I generally wanted to make an anti "gravity gun attacks" turret ( a turret with 0 damage but 500 force, it aims at props launched at me and changes their direction so they don't hit me) . I first wanted it to search all entities close to me and aim at the ones which are going to hit me but I failed at that.
    What I did was:
    1- make a line out of entities position and velocity.
    2- make a sphere with a center at owners pos and a radius of R
    3- put the equations together and see if the line cuts the sphere
    4- if it cuts the sphere, stop the for loop and shoot at the entity.
    I failed because:
    The speed of target is not enough, I need accelration for that. The speed can only work for missles, not for gravity gun attacks(the speed changes because of gravitation, the prop falls down)
    So I tried disabling the Z and calculating in 2D with x and y only(so no gravitational effect and air resistance is not important). It worked somehow but it wasn't what I wanted.

    Now I am trying to calculate the accelration vector and use a formula using it.
    Simply, my system saves the speed vector of the target, then waits for one tick, and saves the second speed vector of the target.
    I get accelration like this: A = V1 - V2 (it is one tick only so I dont divide it to one)
    then I use the formula:
    Position of entity relative to time(t) = V*t + 1/2 * A*t^2 + CurrPos
    And I build a sphere:
    S: (x - CenterX)^2 + (y - CenterY)^2 + (z - CenterZ)^2 = R^2
    and I compose the first formula with the second one:
    S: (VX*t + 1/2*AX*t^2 + CurrPosX - CenterX)^2 + ....... = R^2
    My plan was to find if we can find t (delta>=0)
    If we can find t, the entity will hit me.
    But I wasn't able to solve the equation :S

    So I said "whatever, just stop all gravity gun attacks" and made something that follows these steps:
    1: find all players in the map to an array
    2: check in a for loop if players have grav. gun equipped. if yes, check if the aimentity of them is being held by player. if yes break the loop, set track to the current player. (I also have an idea of checking the players roll and see if it is facing at me but it may not work well)
    3: if the entity being tracked presses first mouse button set EntProp to that players aimentity
    4: if aimentity is not null, fire for 2 seconds long.

    This simply stops all gravity gun attacks made(not only the ones made against me, it stops all of them except my attacks ) but I don't want it. I want the one I mentioned above to work I think my way is right, but I just can't solve those equations

  2. #2
    No u Divran's Avatar
    Join Date
    Jul 2008
    Location
    Sweden
    Posts
    4,582

    Default Re: How to know/predict if an object will hit me or not?

    Try this
    Code:
    Pos = E:pos()
    Vel = E:vel():normalized()
    Dist = owner():shootPos():distance(Pos)
    Pos2 = Pos + Vel * Dist
    Dist2 = owner():shootPos():distance(Pos2)
    if (Dist2 < 200 & Dist < 1000) { #if it's closer than 1000 units and it's about to travel through a sphere 200 units around you...
    #shoot it down
    }
    Edit:
    Also, to get the acceleration you can simply do $Vel, like so:
    Code:
    @persist SpeedVec:vector SpeedNum
    runOnTick(1)
    SpeedVec = entity():vel()
    SpeedNum = SpeedVec:length()
    AccVec = $SpeedVec
    AccNum = $SpeedNum
    SVN Tutorial
    My SVN:
    Code:
    http://divranspack.googlecode.com/svn/trunk/%20divranspack/
    Get dropbox and get 250 MB extra space: Dropbox

  3. #3
    Wire Amateur napalmstrike2007's Avatar
    Join Date
    Feb 2010
    Posts
    43
    Blog Entries
    1

    Default Re: How to know/predict if an object will hit me or not?

    Quote Originally Posted by Divran View Post
    Try this
    Code:
    Pos = E:pos()
    Vel = E:vel():normalized()
    Dist = owner():shootPos():distance(Pos)
    Pos2 = Pos + Vel * Dist
    Code:
    Vector1 = Vector:normalised()
    # is this normalised() operation like:
    Vector2 = Vector/Vector:length()
    #now are the vector2 and vector1 same?
    if that is so, your make the velocity vectors lenght same with the distance between me and the entity, adding it to enitities current position should give us its predicted position after travelling distance between me and it?
    thats a very clever idea, but It can fail because of gravitation(velocity vector changes its direction as the object rises up and falls down, but at the time it is falling down this system shall work, but it is risky )
    I will try it and inform you again.
    Thanks for your help

  4. #4
    No u Divran's Avatar
    Join Date
    Jul 2008
    Location
    Sweden
    Posts
    4,582

    Default Re: How to know/predict if an object will hit me or not?

    Yeah it can fail because of gravity, but that's why I check the distance is less than 1000 too. So that your turret doesn't shoot something on the other side of the map which just happens to be slowly gliding towards you with super ice (or something).
    SVN Tutorial
    My SVN:
    Code:
    http://divranspack.googlecode.com/svn/trunk/%20divranspack/
    Get dropbox and get 250 MB extra space: Dropbox

  5. #5
    Wire Amateur napalmstrike2007's Avatar
    Join Date
    Feb 2010
    Posts
    43
    Blog Entries
    1

    Default Re: How to know/predict if an object will hit me or not?

    I tested this and found out another cool thing: the turret clears your way from any props its like "Masters way must be cleaned die props that stay in his way !! "
    It is a cool feature but I added E:vel():length>1000(1000 isnt enough, maybee 5000 will do the job) to that if statement to prevent this. I also added excludePlayerProps(owner) because it was shooting at props I am trying to catch with the gravity gun Now the only thing left is optimizing it since it uses more than 2400 ops. When I optimite it, add other codes I can publish it but if I add other functions it can become a minge tool. So maybee I shouldn't publish it.
    my previous one had many good features:
    type !fire, it makes it shoot where you look at when you click mouse1
    type !auto for it to track gravity gun attacks
    type !npc for it to kill all npcs in the map less then 3 seconds(uber npc killer, possible minge tool)
    I also added it a checker that checks the owners color, if it is different than (255,255,255) it probably means that someone is trying to track you with the target finder(paint target) and it warns you with an alarm sound.
    I can also add a command !kill playername so it tracks one specific player and kills him/her (But then I thought that it will be a minge tool and won't add it)

  6. #6
    billywitchdoctor.com Whosdr's Avatar
    Join Date
    Dec 2008
    Posts
    2,300

    Default Re: How to know/predict if an object will hit me or not?

    Check its bearing to you is consistent with its normalized velocity?
    .siht daer ot gniyrt emit detsaw ev'uoY

  7. #7
    Wire Sofaking Unsmart's Avatar
    Join Date
    Dec 2008
    Location
    Belgium OR BANland
    Posts
    1,965

    Default Re: How to know/predict if an object will hit me or not?

    Quote Originally Posted by Whosdr View Post
    Check its bearing to you is consistent with its normalized velocity?
    Obj:heading(Me)==Obj:vel():normalized()
    New server IP: 89.238.160.17:27018
    Hologram contraptions 1 Holo contraptions 2 EGP stuff Holo minigun Holo javelin rocket launcher
    Unsmart: I doubt the intelligence of some people.
    Drunkie: Nobody could have said that any better than Unsmart.

    Unsmart: Solece, I totally did your mom yesterday
    Solece: Who hasnt

    Divran: there are more retarded people than there are clever people in this world

  8. #8
    Wire Sofaking Fizyk's Avatar
    Join Date
    Jun 2008
    Location
    Łomianki, Poland
    Posts
    740
    Blog Entries
    1

    Default Re: How to know/predict if an object will hit me or not?

    Quote Originally Posted by Unsmart
    Obj:heading(Me)==Obj:vel():normalized()
    Too precise, probably will never be true. Try rather:

    Obj:vel():normalized():dot((Meos()-Objos()):normalized())>cos(5) - this checks the angle between its velocity and the direction to you against the angle of 5 degrees.

    Obj:vel():normalized() - direction of the object's movement
    (Meos() - Objos()):normalized() - direction to you
    ...:dot(...) - dot product of those two vectors, equal to cosine of the angle between them
    dot > cos(5) - if angle is less than 5 degrees (smaller angle = bigger cosine)

    My programs: BIOS - Alcyone - Calculator - Notepad - Movie Player
    My tutorials: applyTorque - Quaternions - PID controllers
    Some other things I made: FT Chip - RK4 Solar System

  9. #9
    Wire Sofaking Unsmart's Avatar
    Join Date
    Dec 2008
    Location
    Belgium OR BANland
    Posts
    1,965

    Default Re: How to know/predict if an object will hit me or not?

    Quote Originally Posted by Fizyk View Post
    Too precise, probably will never be true. Try rather:
    how about round? (or use the difference between the angles, then an inrange rather than using some rocket science math?)
    Last edited by Unsmart; 03-19-2010 at 11:47 AM.
    New server IP: 89.238.160.17:27018
    Hologram contraptions 1 Holo contraptions 2 EGP stuff Holo minigun Holo javelin rocket launcher
    Unsmart: I doubt the intelligence of some people.
    Drunkie: Nobody could have said that any better than Unsmart.

    Unsmart: Solece, I totally did your mom yesterday
    Solece: Who hasnt

    Divran: there are more retarded people than there are clever people in this world

  10. #10
    billywitchdoctor.com Schilcote's Avatar
    Join Date
    Jan 2009
    Location
    There.
    Posts
    2,006

    Default Re: How to know/predict if an object will hit me or not?

    Can't you just do
    Code:
    distance(Obj:heading(Me),Obj:vel) > vec(30,30,30)
    ?


    [19:16:47]Client "rcdraco" spawned in server
    [19:17:10]rcdraco: hamburgertime
    [19:18:04]rcdraco was killed by worldspawn
    [19:21:50]Dropped "rcdraco" from server

+ Reply to Thread
Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots