G
grossik
Guest
Hi.
I need help. I don't know how calculate position in my racing game.
Does anyone know?
I need help. I don't know how calculate position in my racing game.
Does anyone know?
The problem here will be to figure out the plane along which distances to next point are measured. As I mentioned above the problem can be simplified by projecting the positions, essentially turning the measured area into a line. This probably isn't too complicated on straight sections, but looks to be on curve sections where you are measuring progress along elliptical curves. Although, at least on the sample map provided, it should be possible to simply cheat and measure the curves as right angles turns.first, you class the players according to their presence in an area. The player in zone 6-7 will necessarily be more advanced than the player in the 2-3 zone. If several players are in the same zone, you differentiate them by the distance that separates them from the next key point.
I think you have to pair the zones, (2+3), (4+5), (6+7), etc..
var oth = instance_place(x,y,obj_car);
if(oth!=noone)
{
if(creator.id == other.id){ } else {
if(creator.position < oth.position){
oth.position -= 1;
creator.position += 1;
}
if(creator.position < oth.position){
oth.position += 1;
creator.position -= 1;
}
}
}
I was referring to the direction into which the distance measurement needs to be made. If you look at a group of cars without any context, it is not possible to say which one is leading. You might be able to make an educated guess from directions they are moving into, but that would be just that, a guess. You need to know the positioning of the track section; what is the starting point of that section, and where is the end point. From these you get the forward direction of the track segment, and by projecting car positions onto that line, you will know their racing order. (First vector would be from track section start point to track section end point, and the vector to project would be from track section start point to the car currently under scrutiny.) A projection would also tell you when a car has moved past the end of a section, so you can start tracking it against the position of next one.I'm sorry @NightFrost i don't understand "to figure out the plane along which distances to next point are measured"
Could try putting an object at each bend which creates a line between that and the next connecting object. Then as you pass each one, it calculates the distance you have traveled between the previous and the next one and then you just work out player's position based on the total distance covered using that method?Hi.
I need help. I don't know how calculate position in my racing game.
Does anyone know?
If I did it, I would need help, some example of code.I think what @Desix is proposing would work, but it will be highly intensive in programming terms. Doesn't mean you shouldn't attempt, but it will not be easy and I doubt you will find any usable tutorials out there. My method, while less technically impressive, should also work pretty flawlessly. You just need to manually go through each track and drop your checkpoint line objects where you want them, and assign each one a number.
My method just involves lines (which would be objects) that have a value assigned to it (checkpoint_no = 1) that when you collide with (place_meeting) would set a variable (like race_position = other.checkpoint_no) in that car.If I did it, I would need help, some example of code.
And what is poorly in my way? Make line for all car and according to collision to find out if they overtook or not.My method just involves lines (which would be objects) that have a value assigned to it (checkpoint_no = 1) that when you collide with (place_meeting) would set a variable (like race_position = other.checkpoint_no) in that car.
Those checkmark objects could be sprites with specific masks for precision collision checking or maybe you could come up with a method that draws a line (maybe THIS?) (instead of precision checking a sprite mask). But you would need to make an assortment of angles to accommodate all your turns and directions. Then when you place each object on the room over the track, you would add some creation code into it to assign that checkpoint_no variable.
Then you have scoreboard that accesses each car's race_position variable to do some calculations and then render out the position of each car as compared to the others.
If you need help beyond this, I'd recommend going through some of Shaun Spaulding's tutorials. They aren't geared around racing, but they all typically have quite a bit of info about positioning and collisions (which is the basis behind my idea...).
var ins = instance_create(x, y, obj_overtaking);
ins.creator = id;
x = creator.x;
y = creator.y;
image_angle = creator.image_angle;
var oth = instance_place(x,y,obj_car);
if(oth!=noone)
{
if(creator.id != other.id){
if(creator.position < oth.position){
oth.position += 1;
creator.position -= 1;
}
}
}
I am not sure if you are saying you have a working solution or not...And what is poorly in my way? Make line for all car and according to collision to find out if they overtook or not.
http://imgur.com/mKWgvDm
Code in car:
And code in obj_overtaking (step code):Code:var ins = instance_create(x, y, obj_overtaking); ins.creator = id;
Somehow this I imagined.Code:x = creator.x; y = creator.y; image_angle = creator.image_angle; var oth = instance_place(x,y,obj_car); if(oth!=noone) { if(creator.id != other.id){ if(creator.position < oth.position){ oth.position += 1; creator.position -= 1; } } }
(sorry for my bad English)
Maybe yes. But this is not important now. My code works but still adds and subtracts. So then there are numbers like -450 or 500... I need to change it only once.I am not sure if you are saying you have a working solution or not...
Your method could maybe work too, though I am thinking there might be some issues with driving backwards?
oth.position = clamp(oth.position+1, 1, 5);
creator.position = clamp(creator.position-1, 1, 5);
collided = 0
if ( collision check ) {
if ( collided == 0 ) {
do math;
collided = 1;
}
} else {
collided = 0;
}
This does not work. I really don't know.Looks about right.
You will probably need to set a variable to 0 before the collision - check before math if 0, if yes - do math and set variable to 1.
This is psuedo-code... I am on phone.
Then when collision is ended - change it back to 0.Code:collided = 0 collision check { if ( collided == 0 ) { do math; collided = 1; } }
This might get a bit weird though if a bunch of cars all are meeting around the same space... so it may not work. You may have to come up with another way of only adding/subtracting once.
Used..The initial collided needs to be set in the create event.
And you didn't use my pseudo code, right?
var oth = instance_place(x,y,obj_car);
if(oth!=noone)
{
if(creator.id != other.id) then {
if(collided == 0) {
if(creator.position > oth.position) then {
oth.position = clamp(oth.position-1, 1, 5);
creator.position = clamp(creator.position+1, 1, 5);
}
collided = 1;
}
} else {
collided = 0;
}
}
collided = 0
Now it does nothing.What exactly is happening now?
Sorry, I am at a bit of a loss.Now it does nothing.
This code:Sorry, I am at a bit of a loss.
var oth = instance_place(x,y,obj_car);
if(oth!=noone)
{
if(creator.id != other.id) then {
if(collided == 0) {
if(creator.position > oth.position) then {
oth.position = clamp(oth.position-1, 1, 5);
creator.position = clamp(creator.position+1, 1, 5);
}
collided = 1;
}
} else {
collided = 0;
}
}
I will do it in a different way...Sorry, you may have to scrap my idea about clamping and the collision check. I think you are going to have nothing but trouble with trying to keep track of collisions like this with multiple cars all around each other. Another game dev here may have some better ideas to keep this all working as you have and improve like I was trying, but I am guessing it is going to be an uphill battle.
That said, If you go back to your original method, when you were ending up with huge numbers - were they still in the correct order? I mean, it may have been -450 and 500 (or whatever) - but, if they are still in the correct order, you may have still have something to work with. You would just have to do some math to compare all the car's values to each other and get their place.
I have a feeling they aren't in the correct order, but who knows.
If not - if the order is incorrect, you are sort of back to the drawing board in my opinion. I don't have much else advice if you want to continue with your plan of having the collision lines stay with the car. I and other people offered some other ideas, you may want to explore those.
Somehow like that?I remain convinced that my idea of zone and distance just to the key points is not a bad idea.
The position in a priority list should be
number of the area * 1000 + distance to the key point
exemple:
player 1 : position = 10 * 1000 + 106 = 10106
player 2 : position = 10 * 1000 + 324 = 10324
player 3 : position = 11 * 1000 + 318 = 11318
set the priority of each player :
ds_priority_change(player_priority, "player_x", position);
then sort the name of the player with a loop using ds_priority_find_min