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:
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:
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.