T
trentallain
Guest
Wish there was some from of point_direction_3d(x1,y1,z1,x2,y2,z2), but that wouldn't work. But anyway, I'm trying to somewhat replicate star wars battlefront's spaceship combat (like this:
but not so HD and only with 2 ships, more just gameplay etc) but I am very new to 3D (I pretty much started 2 days ago). I have the camera and model set up, as well as left and right steering.
What I need to add next is vertical movement but I'm not sure what I need to do in order to do that. I have tried:
(global.pan is the horizontal camera angle and tilt is the vertical camera angle)
In case it might help I'll also add my other code:
So what I'm basically aiming for is to move in the 3D direction I am looking at with the camera.
Also as a side thing, how do I find the position of the laser shooters to shoot the laser at the correct position?
What I need to add next is vertical movement but I'm not sure what I need to do in order to do that. I have tried:
Code:
//Step (this is all the code in step)
direction = global.pan
speed = -10
z -= lengthdir_y(speed,global.tilt)
z -= lengthdir_y(1, global.tilt+25) * speed
In case it might help I'll also add my other code:
Code:
///Create
format = vertex_format_create_simple(true,true,true)
model = model_load("xwinggms2.dat",format)
texture = sprite_get_texture(spr_texture1,0)
xangle = 0
yangle = 0//180
zangle = 0
draw_set_lighting(true)
draw_light_enable(0,true)
draw_light_define_point(0, x, y, -100, 500, c_white)
z = 0
//3D camera
camera = camera_create()
gpu_set_zwriteenable(true)
gpu_set_ztestenable(true)
projection_matrix = matrix_build_projection_perspective_fov(-60, -view_get_wport(0)/view_get_hport(0), 32, 32000)
camera_set_proj_mat(camera, projection_matrix)
view_set_camera(0, camera)
camera_set_update_script(view_camera[0], camera_update_script)
global.xmove = 0
//
global.pan = 0
global.tilt = 45
global.distance = 1000
global.camerax = lengthdir_x(lengthdir_x(1, global.pan), global.tilt)
global.cameray = lengthdir_x(lengthdir_y(1, global.pan), global.tilt)
global.cameraz = lengthdir_y(1, global.tilt)
Code:
//Draw
draw_light_define_point(0, x, y, -1000, 2000, c_white)
//
matrix_set(matrix_world, matrix_build(x, y, z, global.tilt-180, -yangle, global.pan+90, scale, scale, scale))
vertex_submit(model, pr_trianglelist, texture)
matrix_set(matrix_world, matrix_build(0, 0, 0, 0, 0, 0, 1, 1, 1))
//
Code:
///camera_update_script
if keyboard_check(vk_right)
{
if global.pan < 360 { global.pan += 1 }
else { global.pan = 1 }
}
if keyboard_check(vk_left)
{
if global.pan > 0 { global.pan -= 1 }
else { global.pan = 359 }
}
if keyboard_check(vk_up)
{
if global.tilt < 360 {global.tilt += 1 }
else { global.tilt = 1 }
}
if keyboard_check(vk_down)
{
if global.tilt > 0 { global.tilt -= 1 }
else { global.tilt = 359 }
}
global.camerax = lengthdir_x(lengthdir_x(1, global.pan), global.tilt+25)
global.cameray = lengthdir_x(lengthdir_y(1, global.pan), global.tilt+25)
global.cameraz = lengthdir_y(1, global.tilt+25)
up_x = -dsin(global.tilt + 25)*dcos(global.pan);
up_y = dsin(global.tilt + 25)*dsin(global.pan);
up_z = -dcos(global.tilt + 25);
matrixlookat = matrix_build_lookat(obj_xwing.x + global.camerax * global.distance,obj_xwing.y + global.cameray * global.distance,obj_xwing.z + global.cameraz * global.distance,obj_xwing.x,obj_xwing.y,obj_xwing.z, up_x,up_y,up_z)
camera_set_view_mat(view_camera[0], matrixlookat)
Also as a side thing, how do I find the position of the laser shooters to shoot the laser at the correct position?
Last edited: