I’m trying to get the position of players in a car game, I understand how to do that, thanks to some very good search results here .But now I’ve a lil doubt.
I’ve setup the box colliders attached to each of 17 new game objects n’ named it chk1,chk2,…n’ so on upto chk17 .This is "Is trigger"ed also .I understand how to check for position of the player ,but, How can I check which object is the active waypoint n’ thus find d next waypoint .Please provide, a quick reply .
Thanks in advance . .
Can anyone point me to any tutorial??Cause I’m still not able to get it to work .
There is more than one approach to this, but the one you choose will probably depend on how many waypoints there are.
For example, you could make all the waypoint trigger objects children of a main supervisor object, which has a kinematic rigidbody. In the supervisor’s script, the OnTriggerEnter function will get called whenever any of the trigggers is activated. The script can then determine if the object that was triggered was the correct waypoint:-
var currentTriggerName: string;
var currentTriggerNumber: int;
function OnTriggerEnter(other: Collider) {
if (other.name == currentTriggerName) {
currentTriggerNumber++;
currentTriggerName = "Trigger" + currentTriggerNumber;
}
}
This relies on the trigger objects being named correctly beforehand. This can be a nuisance if there are a lot of waypoints, especially if you find you need to add extra ones halfway along.
Another way to go is to have a script on each trigger object. This contains a variable that “points” to the next waypoint in the chain:-
// Waypoint.js
var nextWP: Waypoint;
var itsMe: boolean;
function OnTriggerEnter(other: Collider) {
if (itsMe) {
itsMe = false;
nextWP.Activate();
}
}
function Activate() {
itsMe = true;
}
This requires that you link the waypoints together in the editor. However, it may be simpler if you might need to make frequent edits to the track.
In one of the other threads,I found while searching, u had said that,subtracting current waypoint from next waypoint is saved as a vector into another variable, then find,carheading direction ,n’ thus get a dot product of those two , to get a value, which can b used to determine d position n’ also as a wrong way detector .(Great idea btw, it really makes sense)Right now, I’m not getting the perfect values , from start, Dot product’s giving me negative value , i don’t know why??All the time,when v’re going in the real(suppos-ed) direction, it gives negative value, n’ when v’re going in wrong direction , its giving me positive values, at some points ,on track, n’ negative valus, on other points on track .So…Its hard to detect wrong way…this way . I’m sure I’m making a mistake.But can’t find it .I haven’t yet tried to determine the position.
I would like to know , what exactly do you consider as currentwaypoint and nextwaypoint .
I’ve considered it like, currentwaypoint is the one after the waypoint that we just triggered n’ the nextwaypint is the one after the currentwaypoint .
I wonder if ,it is to be considered differntly ,like, the waypoint we jus’ triggered is currentwaypoint and the next waypoint is the nextwaypoint .
If you’re getting the negative of the value you want for the dot product, it just means you are subtracting the vectors the wrong way round. if the right direction is from point a to point b, you get the right way vector with:-
var rightWay: Vector3 = b - a;
As for the current and next waypoint, generally, the waypoints have a prearranged sequence around the track. If the player goes the right way around, then the waypoints will be triggered in this sequence. The current waypoint is the one that has most recently been triggered and the next one is the one after the current one in the sequence.