wadaltmon
Member
Hello!
Background:
I am creating a 3D, isometric RPG. In order to make collisions more expedient, I am using the P3DC extension.
As in most isometric RPGs, the mouse is used to control where the player character will move and what the player will interact with. As such, I implemented a ray casting system that will move an object based on the movement of the mouse; the mouse will move in some direction, the deviation from the center of the screen is found, and the object is moved proportionally to this deviation, and the mouse returns to the center of the screen. The ray cast will then point to the location of this object (referred to henceforth as the player object). This is so I can have traditional RPG movement and interaction (you click on a location to move, or click on an element in the world to interact with it). Take a look at this video to see the kind of movement I mean (a good example is at 2:58):
I went this route because my attempts to simply transform the ray that was being cast failed. I decided that I would create a new object to act as the mouse cursor in the game (since the mouse returns to the center of the screen), so that it would appear directly over where the player object was shown on screen. However, I'm unable to find a way to make it so the mouse movement directly controls how far the object is moved on-screen.
What I mean by this is that the farther away the player object is from the camera view, the farther it would have to move (in terms of x-y coordinates) to correspond to the cursor on screen, whereas the closer it is to the camera view, the less it would have to move. However, I'm unable to find a suitable mathematical formula to do this. As such, when the player object is farther away from the camera view, it seems like the mouse is less sensitive almost. Take a look at this video to see the current system (the green triangle is the triangle with which the raycast collides):
Now for the code I've used.
There are 2 objects: one for the controller (player object) itself, and one that simply controls the position of the camera view.
Controller (player object) create event (unrelated code removed):
Controller (player object) step event:
Controller (player object) draw event (unrelated code removed):
Camera (oCam) object create event:
Camera (oCam) object step event:
I feel I should also explain a few things about these.
1. z never changes, it is always a constant 50.
2. dtc will eventually be able to change so the player can zoom in, but as of right now, it doesn't change.
3. The numbers in the projection as well as the numbers 145 and such just come from me testing the view angle I wanted to keep constant, and what directions on the x-y plane would correspond to "up" on the player's display.
4. with dtc = 500, the distance from the top to the bottom of the screen in real x-y distance is 565.85 as I have measured.
I tried using the "mult" variable to change the sensitivity of movement based on the distance away from the camera object, to no avail (it simply made the mouse really sensitive when it went above the middle of the screen). Here is the code I tried for that:
However, this code did not yield anything but the cursor being way too sensitive while it was far away from the camera, and at a very low sensitivity when it was close to the camera.
I'm sure there is a way to create a raycast such that the place on the level model that the ray connects with will be directly under the mouse cursor; or, there may be a way to scale the movement of my existing object movement system to allow the object to move farther as it gets farther away (and to allow for the mouse cursor to be a separate object that moves in conjunction with this). However, the way to do this... I'm just not seeing. I'd like to see if anyone that has experience in 3D or is seeing something I'm not can help me out with this. Input is greatly appreciated.
Thank you in advance.
wadaltmon
Background:
I am creating a 3D, isometric RPG. In order to make collisions more expedient, I am using the P3DC extension.
As in most isometric RPGs, the mouse is used to control where the player character will move and what the player will interact with. As such, I implemented a ray casting system that will move an object based on the movement of the mouse; the mouse will move in some direction, the deviation from the center of the screen is found, and the object is moved proportionally to this deviation, and the mouse returns to the center of the screen. The ray cast will then point to the location of this object (referred to henceforth as the player object). This is so I can have traditional RPG movement and interaction (you click on a location to move, or click on an element in the world to interact with it). Take a look at this video to see the kind of movement I mean (a good example is at 2:58):
I went this route because my attempts to simply transform the ray that was being cast failed. I decided that I would create a new object to act as the mouse cursor in the game (since the mouse returns to the center of the screen), so that it would appear directly over where the player object was shown on screen. However, I'm unable to find a way to make it so the mouse movement directly controls how far the object is moved on-screen.
What I mean by this is that the farther away the player object is from the camera view, the farther it would have to move (in terms of x-y coordinates) to correspond to the cursor on screen, whereas the closer it is to the camera view, the less it would have to move. However, I'm unable to find a suitable mathematical formula to do this. As such, when the player object is farther away from the camera view, it seems like the mouse is less sensitive almost. Take a look at this video to see the current system (the green triangle is the triangle with which the raycast collides):
Now for the code I've used.
There are 2 objects: one for the controller (player object) itself, and one that simply controls the position of the camera view.
Controller (player object) create event (unrelated code removed):
Code:
z=50;
x=30;
y=30;
sw=display_get_width()/2;
sh=display_get_height()/2;
direction = 0;
xf=210.25;
yf=-164.26;
zf=-422.86;
dtc = 500;
Controller (player object) step event:
Code:
mult = 2;
//MOUSELOOK
x-=lengthdir_x( (mult/2 * (2*sh)/dtc) * ((sh-display_mouse_get_y())/2),145);
y-=lengthdir_y( (mult/2 * (2*sh)/dtc) * ((sh-display_mouse_get_y())/2),145);
x-=lengthdir_x( (mult/2 * (2*sh)/dtc) * ((sw-display_mouse_get_x())/2),235);
y-=lengthdir_y( (mult/2 * (2*sh)/dtc) * ((sw-display_mouse_get_x())/2),235);
display_mouse_set(sw,sh);
Controller (player object) draw event (unrelated code removed):
Code:
d3d_set_projection_ext(oCam.x-210.25,oCam.y-164.26,z+422.86,
oCam.x,oCam.y,z,0,0,1,45,view_wview[0]/view_hview[0],1,262144);
xd=xf/dtc;
yd=-yf/dtc;
zd=zf/dtc;
dis=p3dc_ray_still(level_colid,x,y,z+5,xd,yd,zd);
Camera (oCam) object create event:
Code:
dtc = 500;
sw=display_get_width()/2;
sh=display_get_height()/2;
Camera (oCam) object step event:
Code:
if (keyboard_check(ord('W'))) {
x-=lengthdir_x(2,145);
y-=lengthdir_y(2,145);
}
if (keyboard_check(ord('S'))) {
x-=lengthdir_x(2,145+180);
y-=lengthdir_y(2,145+180);
}
if (keyboard_check(ord('A'))) {
x-=lengthdir_x(2,145+90);
y-=lengthdir_y(2,145+90);
}
if (keyboard_check(ord('D'))) {
x-=lengthdir_x(2,145-90);
y-=lengthdir_y(2,145-90);
}
I feel I should also explain a few things about these.
1. z never changes, it is always a constant 50.
2. dtc will eventually be able to change so the player can zoom in, but as of right now, it doesn't change.
3. The numbers in the projection as well as the numbers 145 and such just come from me testing the view angle I wanted to keep constant, and what directions on the x-y plane would correspond to "up" on the player's display.
4. with dtc = 500, the distance from the top to the bottom of the screen in real x-y distance is 565.85 as I have measured.
I tried using the "mult" variable to change the sensitivity of movement based on the distance away from the camera object, to no avail (it simply made the mouse really sensitive when it went above the middle of the screen). Here is the code I tried for that:
Code:
if ( (oCam.x >= x) && (oCam.y >= y)) {
xback = oCam.x-lengthdir_x(565.85/2, 325);
yback = oCam.y-lengthdir_y(565.85/2, 325);
disback = abs(point_distance(xback, yback, x, y));
mult = 2 * (disback / 565.85);
}
else {
mult = 4;
}
However, this code did not yield anything but the cursor being way too sensitive while it was far away from the camera, and at a very low sensitivity when it was close to the camera.
I'm sure there is a way to create a raycast such that the place on the level model that the ray connects with will be directly under the mouse cursor; or, there may be a way to scale the movement of my existing object movement system to allow the object to move farther as it gets farther away (and to allow for the mouse cursor to be a separate object that moves in conjunction with this). However, the way to do this... I'm just not seeing. I'd like to see if anyone that has experience in 3D or is seeing something I'm not can help me out with this. Input is greatly appreciated.
Thank you in advance.
wadaltmon