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

Thread: How to find out if player is aiming at a holo?

  1. #1
    Lifetime Supporter
    Nikita will become famous soon enough Nikita's Avatar
    Join Date
    May 2009
    Posts
    676

    Default How to find out if player is aiming at a holo?

    Once again I fail at angles. Is there any formula that I can use to know if or not a player is aiming at a certain holo with arbitrary coordinates?

  2. #2
    Wire Sofaking
    Hitman271 has a spectacular aura about Hitman271 has a spectacular aura about Hitman271's Avatar
    Join Date
    Feb 2008
    Location
    Why? You looking for somebody?
    Posts
    705

    Default Re: How to find out if player is aiming at a holo?

    aimEntity( holoEntity( whateverHologramIndex ) )
    Quote Originally Posted by Anticept View Post
    This is not some place where you can toss your dick around and expect people to suck it.
    Community Gpu Thread. Post Yours!

    Bouncy Ball

  3. #3
    Wire Sofaking jacoby6000 will become famous soon enough jacoby6000's Avatar
    Join Date
    Feb 2008
    Location
    behind you when you aren't looking
    Posts
    638

    Default Re: How to find out if player is aiming at a holo?

    This will give you the angle part, you can make the tolerance stuff urself I think.

    Code:
    TargetAngle=Player:shootPos()-holoEntity(I):pos()
    CurrentAngle=Player:eyeAngles()
    if(CurrentAngle:inRange(TargetAngle-Tolerance,TargetAngle+Tolerance){
     Player is aiming at holo
    }else{
     Player is not aiming at holo
    
    Quote Originally Posted by Garrysmod View Post
    Warning: You're trying to render in the wrong place. This doesn't play nice with multi-core rendering, so we're not going to let you draw here.
    I'm not stupid!
    In [his] experience that was a sentence never to be uttered except to prove its own inaccuracy
    --Orson Scott Card

  4. #4
    Wirererer timas will become famous soon enough timas's Avatar
    Join Date
    Apr 2007
    Location
    Vennesla, Norway
    Posts
    165

    Default Re: How to find out if player is aiming at a holo?

    Oh god, i did all theese calculations with trigonometry xD Didden't know it whas this simple.

    If you'd been listening you'd know that Nintendos! pass trough everything! - Colonel Jack. O'Niel
    Good news everyone!
    I have invented a device that makes your read this in your head, in my voice.

  5. #5
    Lifetime Supporter
    Nikita will become famous soon enough Nikita's Avatar
    Join Date
    May 2009
    Posts
    676

    Default Re: How to find out if player is aiming at a holo?

    Sorry, neither works because there is no inRange for angles, and aimEntity does not accept an entity as a parameter except the one before ':'.

    Thanks for Player:shootPos() though, I totally forgot about that one.

  6. #6
    Master of Mars


    Magos Mechanicus will become famous soon enough Magos Mechanicus will become famous soon enough Magos Mechanicus's Avatar
    Join Date
    May 2008
    Posts
    834

    Default Re: How to find out if player is aiming at a holo?

    First up, use a vector dot product to get the angle between the player's camera facing and the direction from the player to the hologram.
    Toholo = Hologram:pos() - Player:shootPos()
    Angle = acos( Player:eye():dot(Toholo:normalized()) )

    Now, you could just check whether the angle is smaller than a fixed amount, but if your hologram is very far away it might be within 5 degrees or whatever even though you're pointing far away from it. To compensate for that, we need trig. We know (or at least can get with holoScaleUnits(Index) ) the size of the hologram. For the most simplistic collision checking, we can assume the hologram is a sphere with this radius. So we draw up a right triangle where one side is the line from player to hologram and the other is that radius, then use arctangent to find the angle we're missing. Now we have an angle tolerance that scales to the hologram's distance from the player.

    Radius = holoScaleUnits(Hologramindex):length()
    Angletolerance = atan( Radius/Toholo:length() )
    if(Angle < Angletolerance){ Player is looking at hologram, do stuff }
    Last edited by Magos Mechanicus; 02-08-2010 at 05:10 PM. Reason: Mixed up atan() arguments.
    I can wire anything directly into anything! I'm the Professor!
    -Professor Hubert Farnsworth

  7. #7
    Drone Madman
    Lyinginbedmon has a spectacular aura about Lyinginbedmon has a spectacular aura about Lyinginbedmon's Avatar
    Join Date
    Mar 2009
    Location
    England
    Posts
    2,651

    Default Re: How to find out if player is aiming at a holo?

    I just use

    Des=Holo:pos()
    Pro=Owner():shootPos()
    Pro+=Pro:distance(Des)*Owner:eye()
    if(Pro:distance(Des)<=X){do stuff}
    The Olympus Technologies drones, totally not SkyNet in Gmod form.
    Cronus: The Ultimate Drone, definitely SkyNet in Gmod form.
    The gBrain Project, the drone controls system that thinks it's better than you

    Need to learn how to make your own drones? Check out Drones with a Mad Scientist for my tutorials on how to do it.

  8. #8
    No u

    Divran is a jewel in the rough Divran is a jewel in the rough Divran is a jewel in the rough Divran is a jewel in the rough Divran's Avatar
    Join Date
    Jul 2008
    Location
    Sweden
    Posts
    2,456

    Default Re: How to find out if player is aiming at a holo?

    Quote Originally Posted by Lyinginbedmon View Post
    I just use

    Des=Holo:pos()
    Pro=Owner():shootPos()
    Pro+=Pro:distance(Des)*Owner:eye()
    if(Pro:distance(Des)<=X){do stuff}
    Me too.

    I even did this for my lua aimbot (which I made yesterday) to determine who is closest to my crosshair and then lock on to that person (edit: note: closest to my crosshair, not aimpos. edit2: imagine a line drawn from my crosshair to my aimpos. whoever is closest to that line that's better explained.)
    PewPew (New GCombat) | SVN Tutorial | EGP v3
    MY SVN LINK:
    Code:
    http://divranspack.googlecode.com/svn/trunk/%20divranspack/
    


    Thanks for clicking, everyone!
    http://www.minerwars.com/?aid=927
    But if I get even more clicks, I get the full game, so keep at it!

  9. #9
    Lifetime Supporter
    Nikita will become famous soon enough Nikita's Avatar
    Join Date
    May 2009
    Posts
    676

    Default Re: How to find out if player is aiming at a holo?

    Thanks Magos, that really helped!

    You are all nice!

  10. #10
    Expressionism 2.0

    Syranide has disabled reputation Syranide's Avatar
    Join Date
    Mar 2007
    Location
    Sweden
    Posts
    4,504

    Default Re: How to find out if player is aiming at a holo?

    If you want to know ONLY when a player has the target on a holo, check out "ray-triangle/quad/cube/etc intersection" equations.

    Otherwise, "ray point-distance" equqations can be used to just know how far off you're aiming. Meaning, you can for instance use the size of the holo to estimate a radius.

+ Reply to Thread
Page 1 of 2 1 2 LastLast

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