JavaScript Racing Game Barrier Help (1 Viewer)

nathan98

New Member
Joined
Mar 31, 2015
Messages
14
Gender
Male
HSC
2016
Hi im in year 11 and for SDD we have to make a game. I have already made the racing map for my game in photoshop. Could someone please tell me how to make the barriers solid so you cant drive through them. Or could someone tell me how to make the car slow down if its driven off the track. Im not sure which method I will implement. Here are screenshots of my game so far.

Screen Shot 2015-06-14 at 5.37.58 pm.png
Screen Shot 2015-06-14 at 5.37.52 pm.png
 

dan964

what
Joined
Jun 3, 2014
Messages
3,473
Location
South of here
Gender
Male
HSC
2014
Uni Grad
2019
Just find the distance between the barrier and the car. If it is 0, then they have hit the barrier.
Just also check the distance between the centre of the road and the car, if it is greater than half the width of the road, then it is off road.
 

nathan98

New Member
Joined
Mar 31, 2015
Messages
14
Gender
Male
HSC
2016
Just find the distance between the barrier and the car. If it is 0, then they have hit the barrier.
Just also check the distance between the centre of the road and the car, if it is greater than half the width of the road, then it is off road.
Ive read further into collision detection. I understand the concept but I dont know how to implement it
 
Last edited:

keepLooking

Active Member
Joined
Aug 25, 2014
Messages
477
Gender
Male
HSC
2015
Since your game is playing only in a confined box, you can limit the x values to be in a range. For example 200-800, when the car is <200, set the player back to 180 and if it is >800, set the player back to 780.

To make the car slow down, it will depend on the code.
 

dan964

what
Joined
Jun 3, 2014
Messages
3,473
Location
South of here
Gender
Male
HSC
2014
Uni Grad
2019
http://www.quirksmode.org/js/findpos.html

you will need a couple of things to get using document.getElementById(the id of the car)
I. the width of the car (as the degree of error, as it most likely will measure either the centre or top left of the corner, test which in IE, Chrome etc.)
II. the width of the road.
III. the position of the edge of the road from the left edge of the screen.
(for corners you need the distance vertically as well using vectors)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top