Hey, YES you can
It just neds some work
My math is poor and I cobbled this together from online Trig help so forgive my comments. If someone would like to refine this please feel free. It works for yRotated plains/objects, perfect sliding collision. Basically you take advantage of the fact that the plain is infinately flat, so you can only hit 2 sides of it. Then you use the Object's stored YRotated angle to work out the sliding collision data based on the vector of your player when he hits it. It only REALLY works if you restrict the collision to ONE side only, otherwise you can get your arse stuck in it when you turn on the spot.
I have a loader somewhere that creates these objects from (specially created) Limbs of a 3ds/x object and have used it successfully a winding race track. I'll do a tutorial if anyones interested
It would be great if someone clever could take this and update it for full 3d collisions (for hills and everthing!)
Set window on
set window layout 1,1,1
sync on
Rem Declare Constants
Dim VectorCar#(2) : Dim VectorObj#(2) : Dim VectorOld#(2) : Dim Vn#(2)
VX = 0 : VZ = 1
Rem Make the Player
Make object box 1, 50,50,50
color object 1, rgb(100,0,0)
position object 1,0,0,0
REM make rotated plains to collide with
Make object plain 2, 1000,100 : Position object 2, 0,0,500
Make object plain 3, 1000,100 : Position object 3, 0,0,1500
Make object plain 4, 1000,100 : Position object 4, 0,0,2500
Make object plain 5, 1000,100 : Position object 5, 0,0,3500
Rem YRotate the Plains as desired!!!
yrotate object 2,135
yrotate object 3,278
yrotate object 4,66
yrotate object 5,143
x# = 0 : z# = 0
a# = 0
Do
Rem Store Old values
oldx# = x# : oldz# = z#
Rem hanlde Player input
if leftkey() = 1 Then a# = Wrapvalue(a#-3)
if rightkey() = 1 Then a# = Wrapvalue(a#+3)
if Upkey() = 1 Then x# = NewXValue(x#,a#,10) : z# = NewZValue(z#,a#,10)
Rem Position and rotate our object (car ahem)
Position object 1,x#,0,z#
yrotate object 1, a#
Rem Position Our camera
position camera object position x(1),object position y(1)+50,object position z(1)
set camera to object orientation 1
move camera -100
point camera object position x(1),object position y(1),object position z(1)
Rem Check for collisions
ObjectHit = object collision(1,0)
if ObjectHit > 0
Print "HIITNG!! "; ObjectHit
Gosub HandleCollisions
EndIf
sync
Loop
end
HandleCollisions:
Rem get the angle of the object we hit...
ObjectHitAngle# = object Angle y(ObjectHit)
Rem Calculate the length of our car vector which is at position x,z from origin oldx,oldz
Rem ` in other words this is the distance from the last position to the new position
vLength# = sqrt((x# - oldx#)^2 + (z# - oldz#)^2)
if vLength# > 0
Rem define my two vector Objects for the car and the object normal
VX = 0 : VZ = 1
Dim VectorCar#(2) : Dim VectorObj#(2) : Dim VectorOld#(2)
Rem in other words, make out that the Old Pos was 0,0,0 and go from there
VectorCar#(VX) = x# - oldx#
VectorCar#(VZ) = z# - oldz#
Rem Get the Object normal Vector
VectorObj#(VX) = NewXValue(oldx#,ObjectHitAngle#,vLength#) - oldX#
VectorObj#(VZ) = NewZValue(oldz#,ObjectHitAngle#,vLength#) - oldz#
Rem Get the scalar DotProduct And....
Rem ... Multiply it by the Object Vector (VectorObj) to
Rem get the component of the car vector that is perpendicular to the surface of the object.
Rem We create a new vector out of this multiplying the object Vector by the DotProduct Scalar
Dim Vn#(2)
Vn#(VX) = ((VectorCar#(VX) * VectorObj#(VX) + VectorCar#(VZ) * VectorObj#(VZ))/ vLength#^2) * VectorObj#(VX)
Vn#(VZ) = ((VectorCar#(VX) * VectorObj#(VX) + VectorCar#(VZ) * VectorObj#(VZ))/ vLength#^2) * VectorObj#(VZ)
print "x# = ";x#;" and z# = ";z#
x# = x# - Vn#(VX)
z# = z# - Vn#(VZ)
`RemStart
set cursor 0,0
Print "oldx# = ";oldx#;" and oldz# = "; oldz#
Print "ObjectHitAngle# = ";ObjectHitAngle#
Print "Length of vector = "; vLength#
Print "VectorCar#(";VectorCar#(VX);",";VectorCar#(VZ);")"
Print "VectorObj#(";VectorObj#(VX);",";VectorObj#(VZ);")"
Print "DotProduct ( Scalar value = cos(theta) )= ";(VectorCar#(0) * VectorObj#(0) + VectorCar#(1) * VectorObj#(1))/ vLength#^2
Print ""
Print "Explination of values:"
Print "Values range from 1 to -1."
Print "If the two input vectors are pointing in the same direction, then the return value will be 1."
Print "If the two input vectors are pointing in opposite directions, then the return value will be -1."
Print "If the two input vectors are at right angles, then the return value will be 0."
print ""
Print "Our New Vector Vn = ("; Vn#(VX);",";Vn#(VZ);")"
Print "So we can find where we are supposed to be by TAKING AWAY the new vector (VN#) from VectorCar#"
Print "(VectorCar# - Vn#)"
print "or adding the opposite of vector Vn"
Print "x = ";x#;" and z# = ";z#
`RemEnd
EndIF
Return