Just to show that I'm still at it an update:
I made the opponent have smooth turning. This was a difficult task and took me all day to figure out...as always, the solution is simpler than you firs think it is. I had to refamiliarise myself with trigonometry, which I had like 3 lessons on during my GCSEs by a chav maths teacher who was more interested in talking to chavs than teaching.
Added powerups - not modelled them yet. What needs to be added is a 'destroy' scenario, just so when the power-up disappears, it doesn't look tacky. I was going to do power-ups where you get a brief boost, like in Hydro Thunder, but then, I don't want it to be like every other arcade racing game out there - instead you get miniature permanent stat increases that are saved for each race. This means instead of selecting new boats - yours gets better based on your racing. Your opponent can collect these, but their increases aren't permanent, I'm not that cruel. Also, it means, another factor for difficulty - if I miss the first power up, the opponent might get the second, meaning I have to out maneuver him better.
In Game Menu + Reset button. For 'reset' I though it was maybe too generous to bounce the boat or repositioning it to the nearest marker. It's meant to be a game of skill, so if you're stuck, start again you lazy bums.
Joint suggestion of The Slayer and Butter Fingers.
Rotating the boat based on speed. Butter fingers'
suggestion.
To Do (For the mechanics):
Currently working with Newton Physics - I won't bother with the ramps until that's implemented. This ought to make the game more realistic.
In Game Menu is slow, DBP built in text commands are slow anyway, as I found out when I programmed a text adventure, the D3D plugin's text commands are faster and sexier. I will replace all text with that.
I think what I'm going to do is once this is finished - is to go through the creation process and write it down in a tutorial, after all, I've not written a tutorial for a long time.
But for now, I'll just post up useful code snippets, so for today:
Smooth Rotation for an AI object.
My solution took me ages to figure out. Generally when an AI follows a way-point, you find yourself using:
point object boat, cx, cy, cz
move object boat, speed...
But as you'll all notice when if moves to the next check point, it's a sudden jolt of rotation, which is unrealistic and doesn't look nice. Essentially you have to make an object point at another object in a whole different way, with a helpful hand from trigonometry.
This is what you need:
angle = ATANFULL(x1 - x2, y1 - y2)
yrotate object boat,curveangle(angle, object angle y(boat), 5)
atanfull is the trigonometry part of the code, x1 and y1 are the target positions (use 'x' and 'y' if it's 2D, or 'x' and 'z' if it's 3D). x2 and y2 is the current position. The angle returned is based on the values of 'x' and 'y' so this is the angle being returned:
If the current boat position isn't subtracted, then the angle would only be relative to 0,0.
So all you need to do is rotate your object on the y-axis with the returned value for it to point at the target object. All that's needed is a 'curveangle', target destination is 'angle', current value is the current angle of the object, the speed ought to be slow enough for the transition to be noticeable, so 5 is good enough.
Here is a code snippet to test the code:
Rem Project: Trigonometry
Rem Created: Wednesday, August 18, 2010
Rem ***** Main Source File *****
`Start up
cls
sync on
sync rate 30
`3d locations
dim x(3)
dim y(3)
dim z(3)
`3 box objects
make object box 1, 50,50,100
make object box 2, 50,50,50
make object box 3, 50,50,50
`reposition 2 of them
position object 2, -100, 0, -100
position object 3, -200, 0, - 150
do
`record positions of all 3 objects
x(1) = object position x(1)
y(1) = object position y(1)
z(1) = object position z(1)
x(2) = object position x(2)
y(2) = object position y(2)
z(2) = object position z(2)
x(3) = object position x(3)
y(3) = object position y(3)
z(3) = object position z(3)
`Perspective camera view
position camera x(1)+200, y(1)+200, z(1)+200
point camera x(1),y(1),z(1)
`Show angle
text 0,10, "angle = " + str$(angle)
angle = ATANFULL( x(2) -x(1), z(2) - z(1))
`Rotate object 1 at a curveangle equating to ATANFULL
yrotate object 1,curveangle(angle, object angle y(1), 4)
`Control 'Waypoint'
if upkey() = 1 then move object 2,10 : move object 1, 10 `Moves follow object
if downkey() = 1 then move object 2,-10 : move object 1, 10 `Moves follow object
if leftkey() = 1 then turn object left 2,5
if rightkey() = 1 then turn object right 2,5
sync
loop
Newer screenshots:
Click!