NoobsWeStand
Member
Hello
I am trying to make a simple 3D car game that uses a 3d collision dll. I am trying to get it so that the car will rotate based on the normal of the face that it is colliding with.
I tried googling, but that doesn't seem to get me anywhere. I have been guessing and checking for around and hour
Here is my code:
xvel, yvel, and zvel are the velocities in the respective axis
The car rotates on the z axis when you press A and D
c_raycast_world() returns true if something was hit
c_hit_n*() returns a normal component of the face that was hit
What the car does
If you need the source code, it can be found here: https://www.dropbox.com/s/39uhar2cq4bdxw1/racergame2.gmz?dl=0
I am trying to make a simple 3D car game that uses a 3d collision dll. I am trying to get it so that the car will rotate based on the normal of the face that it is colliding with.
I tried googling, but that doesn't seem to get me anywhere. I have been guessing and checking for around and hour
Here is my code:
Code:
if(c_raycast_world(x,y,z,x+xvel,y+yvel,z+zvel,1)){
nx = c_hit_nx()
ny = c_hit_ny()
nz = c_hit_nz()
dot = dot_product_3d(xvel, yvel, zvel, nx, ny, nz);
xvel = (-dot*nx + xvel)//*0.4;
yvel = (-dot*ny + yvel)//*0.4;
zvel= (-dot*nz + zvel)//*0.4;
dot = dot_product_3d(nx, ny, nz,0,0,-1);
yrot=-dot*ny*dsin(zrot)*180/pi//-sign(dot)*((nx+ny)*180/pi)*dsin(zrot)//sign(ny+nx)*(1+dot)*dsin(zrot)
xrot=-dot*nx*dsin(zrot)*180/pi//sign(dot)*((nx+ny)*180/pi)*dcos(zrot)//-sign(ny+nx)*(1+dot)*dcos(zrot)
show_debug_message(yrot);
}
x+=xvel
y+=yvel
z+=zvel
zprevious=z
The car rotates on the z axis when you press A and D
c_raycast_world() returns true if something was hit
c_hit_n*() returns a normal component of the face that was hit
What the car does
If you need the source code, it can be found here: https://www.dropbox.com/s/39uhar2cq4bdxw1/racergame2.gmz?dl=0