Download the sample script here.
Download the sample project here, let's use this project as the base for this tutorial.
We will need the following objects to make this code work:
here we will store the possible targets
this will be the interval of the targets search
this object will give offset positions around the target
this is just an variable to help us create an rotation effect for the target HUD, we will increase it and apply to the Y value of the targetAux object rotation
this will set the actual target so we can kid with it :)
When the script loads we should create the object, choose an model with small volume to avoid collisions with other things, we also set this object to be invisible, without collisions and with freezeposition set to true, the wait(500) it's an single delay to avoid script crash at first start, because when game finishes loading the object creation can fail:
Ok, first let's search for the possible targets, in the tick let's check if the timer variable (timeWaitSearchTargets) it's less than zero, then we will reset it to 300 and search for the targets, so each 300 ms we will update the targets list:
Now we will reset the actual target to nothing and run the targets list to see what vehicle is close enough to the aim, we will do it only if user is pressing Aim key and if the targets list exists:
I'm using this method to find the targets.
Now that we have our target we can draw the checkpoint around it:
How it works:
First we set the targetAux object position to player position, you can use current camera position, but the result its almost the same
Then we set the rotation of this object to be the same of the camera
Now we just need to use the method GetOffsetPosition to detect the position around it and based on this we can define the Offset position around the target:
To get the position above the target:
Bellow target:
on the Left:
on the right Right:
This is an simple idea that works very fine, isn't the best option but works fine :)
You can use lights and coronas too, the result will look better.