Detecting If Vehicle Approaches Person
#1

Code!

Hey,

With this code above I'm trying to see if a velocity vector will intersect with a players position. I want to be able to detect if somebody is driving at a player when they press KEY_FIRE, however, this does not appear to work at all by doing the following steps:
  • Normalize the velocity vector so it has length 1.0
  • Get the distance between the vehicle and the player
  • Multiply the velocity vector to be that length
  • Calculate a projected point by adding the scaled velocity vector to the vehicles position
  • Finally, check if the projected point is in range of the player
My understanding tells me this should work? Is my understanding of this vector magic incorrect?

Thanks for any help!
Reply
#2

I suggest you to use GetPlayerCameraFrontVector, since you can get a more accurately projectile position based on the player camera.

https://sampwiki.blast.hk/wiki/GetPlayerCameraFrontVector
Reply
#3

Quote:
Originally Posted by CyNiC
Посмотреть сообщение
I suggest you to use GetPlayerCameraFrontVector, since you can get a more accurately projectile position based on the player camera.

https://sampwiki.blast.hk/wiki/GetPlayerCameraFrontVector
Thanks for the suggestion, however the players camera direction can be changed with the flick of the mouse. It would work nicely if the camera always faced forward.
Reply
#4

Any other suggestions? Pwetty pwease.
Reply
#5

I know this post is old, but I've seen recently people wanted the same thing

- Project a point infront of the player
- Check the distance between the vehicle and player
- Check the angle between the vehicle and player or of vehicle
If the angle is in a range that the vehicle is going left or right, and the vehicle has velocity, then yes they drived passed the player
If the angle is directly inversely proportional with a range to the player then the vehicle is coming straight to them, if not, then they are going away from them
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)