Download the sample project here, let's use this project as the base for this tutorial.
We have an simple way to detect targeted peds, its the approach Player.GetTargetedPed:
With this strategy and an gun (something that will make you capable to see the aim camera, for instance an pistol or even an brick) you can detect the targeted ped, but its as well a lot imprecise, for instance if you aim at an automobile that has an driver, he will be detected as the target even if he is away from center of aim.
Also this strategy never detects the peds that are Dead or in Ragdoll state.
My notion consists in get all achievable targets, save then on an list, run this list and see who is closer to the center of the aim.
Very first lets develop our list of feasible targets, lets commence with peds, this will be an international object so we can access it in the tick:
Now lets fill this list when the player press the aim button, so in the keydown event lets check for appropriate mouse click and fill the list:
Now comes the primary component, run the list in the tick and calc who is closer to center of aiming:
So, what is taking place at every single line?
- If Game.isGameKeyPressed(GameKey.Aim) AndAlso Exists(pedsToTarget) Then
here we check if the user is aiming and if the list is prepared to be employed
- Dim dist As Double
- Dim comparePosition As Vector3
- For Each p As Ped In pedsToTarget
- If Exists(p) AndAlso (p <> Player.Character) Then
- dist = p.Position.DistanceTo(Game.CurrentCamera.Position)
- comparePosition = Game.CurrentCamera.Position + Game.CurrentCamera.Direction * dist
- If p.Position.DistanceTo(comparePosition) < .five Then
- p.ForceRagdoll(2000, Accurate)
- p.ApplyForce(Vector3.WorldUp * .five, Vector3.WorldNorth)
- msg("detected", ten)
This is an exemplification of the calc:
The most significant difficulty with this approach is that we will get targeted peds that are behind walls and when the ped is fallen on ground the ped position is ~.five more than what we anticipate as ped pos, this indicates that you require to aim a small up when he is fallen on ground.
The same thought can be utilized with cars, but to be much more precise we will need to have to examine some added positions not just the center of the vehicle:
we will need this added variable in the tick:
we do the standard center position check:
and we evaluate to the "front position" too employing GetOffsetPosition to receive this position:
we multiply the Y (width) dimension of the model with .5 to get the half of the width and with relativeFront vector (a single step forward)
we do the same with back, top, left and correct position of the automobile:
This tends to make much more easy to target the car when it is big like a bus or a truck, i personally favor to verify just the center position, in excellent portion of circumstances is enough.
Download the Script of this tutorial.
[TUT-IV] Detecting Targets (peds, vehicles and objects)
9out of 10 based on 10 ratings. 9 user reviews.
9out of 10 based on 10 ratings. 9 user reviews.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.