Tag Info

New answers tagged

0

You should do a bounds check as you mentioned then reduce the velocity so you don't get shaky behavior. You kind of got it but I'm not sure what displacement does. //This code goes after velocity is set if (position.x > 50) { position.x = 50; //If we're heading towards the bounds, stop if (velocity.x > 0) velocity.x = 0; } else if ...


0

Augment your finish line point with a direction vector representing the "forward" direction. Then, instead of: if (Vector2.Distance (finishline.position, car.position) != 0) [...] Do: if (Vector2.Dot(car.position - finishline.position, finishline.direction) > 0) [...] Note, if the direction happens to be aligned to a cartesian axis, say +X, the ...


0

This wouldn't answer the question of measuring the distance but for the scenario that you described, I find that placing a collider as trigger on the finish line and checking OnTriggerEnter in your car would be a better solution rather than calculating the distance. For distance check, Dexyne is totally correct but you could also check using the ...


-1

Update – My bad, as @DMGregory says the value of a distance cannot be negative (and it makes sense). As @Kimserey and I says, you can use a trigger. Probably better in this case and easier to use. when the distance between the car and the finish line hits or goes under 0 I think the problem is your if statement. Your test should be: if ...


0

The way I handle these kinds of 2D physics is to process the X and Y components of the vector separately. That way if a collision occurs, I know which direction the collider was moving along based on the sign and component of the velocity vector I am processing. Then when a collision occurs, you can modify the velocity on the appropriate axis. Changing the ...



Top 50 recent answers are included