Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Simple Movement

Author
Message
Comp Guru 910
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location:
Posted: 28th Dec 2007 02:38
Hello, sorry for yet another nub like post. But I was wondering if someone could point me in the direction of a good tutorial, or even a basic code script that explains how to make a 3rd person movement? I have written some code, but its only front back, strafe right and strafe left and I dont really understand the logic behind the strafe left and right considering I just got it off of a darkbasic tutorial. What i need is so that you can look with the camera, and when you hit the up arrow the character will move in that direction.

Here is what I have


Also, in there I have started the sparkys collision, but it doesnt work the way that db's collision works. How do you know when collision is detected. Like, if you wanted to know if collision happened between two objects with db the code would be

if (dbObjectCollision(first object,second object) {
dbpositionobject (first object, x,y,z);
}

How do you accomplish the same task with sparkys?

typos...
The Mayflower
16
Years of Service
User Offline
Joined: 17th Dec 2007
Location: Plymouth, Massachusetts
Posted: 28th Dec 2007 03:49
I've got just your thing!



If you run this you can see the cube move according to the arrow keys. You can't really see that it's moving, but I assure you, it's moving!!!

The camera lags a little behind because of positioning it -15 or +15 to either objz or objx when the keys are pressed. Changing it to 16 or 14 might help.
Comp Guru 910
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location:
Posted: 28th Dec 2007 14:48
Thanks for the help mayflower, but thats not what I was looking for. I have managed to get my cube to move with the arrow keys. What im trying to do is make it so that when I move the mouse, it will rotate the sphere I have made accordingly and position the camera behind the sphere.

typos...
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 28th Dec 2007 15:14
Comp Guru - I don't do all that. I for a strafe left do

dbTurnCameraLeft(90);
dbMoveCamera(How Much to Strafe);
dbTurnCameraRight(90);

Taa daaa No Applause Necessary (because I know its a fudge but it works for me)

Comp Guru 910
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location:
Posted: 28th Dec 2007 15:38
I have manage to get the camera to rotate on its Y axis, but, its only if I move my mouse from the upper left hand corner to the lower right, or my lower right to my upper left. Does anyone know a way of doing this to make the camera rotate left or right when I move my mouse left or right?



typos...
tempicek
16
Years of Service
User Offline
Joined: 27th Nov 2007
Location: Prague
Posted: 28th Dec 2007 19:17
Quote: " Does anyone know a way of doing this to make the camera rotate left or right when I move my mouse left or right?"


I assume you know how much the mouse moved. So you can use functions dbTurnCameraLeft and dbPitchCameraUp to rotate the camera by some angle determined by mouse movement. Or maybe you wanted something else?
Comp Guru 910
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location:
Posted: 28th Dec 2007 23:01
As far as I know though, db doesnt have a built in function for mousemoveleft or mousemoveright. Thats my problem. I can get it (hence the code) to rotate the camera left or right, but I can only do it if mouseX Y or Z change, not left or right, and up or down.

typos...
Woozl
16
Years of Service
User Offline
Joined: 21st Dec 2007
Location:
Posted: 28th Dec 2007 23:23
Hello Comp Guru 910,

There are several pre-made functions for camera and object movement/rotation.

I use the following for Character Movement:


For Camera Management I use :


I should note, the dbMoveObject(...) series of functions DO move on all three axes.

This means if your object is tilted slightly up or down, as well as turned left or right, it will be moved up or down the Y-axis as well as along the x and z axes.

There are a few ways to overcome this if you want to move only on a flat plane (like along the ground).

MY preferred method (to avoid a lot of sin/cos math) is simply to save the Y position of the object before moving it, then restore it with a call to dbPositionObject(...) after the dbMoveObject(...).

Yes, the 'call to dbPositionObject' approach creates some overhead, though I'm thinking not much more than doing the sin/cos math required for movement limited to 2 axes (I have not tested this and I am no code optimization guru, heh, so I could be way off on that statement)


This is how I do it:


If you are moving along an uneven terrain, you can use this code instead, to adjust the Y position of the moved object to the same relative height above the terrain at its new position:



If someone who understands code efficiency better than I do would care to post a better method for doing this, please do! I'm always willing to learn from a master!

I'll leave it as an exercise for you, to set up key and mouse handling.

I hope this helps someone out there.

Regards,
Woozl
Woozl
16
Years of Service
User Offline
Joined: 21st Dec 2007
Location:
Posted: 28th Dec 2007 23:34 Edited at: 29th Dec 2007 01:09
Hello again Guru and all,

Yes there are existing functions to handle Mouse Movement:

dbMouseMoveX(), dbMouseMoveY() and dbMouseMoveZ() even.

These functions return an integer indicating the difference between last position of mouse and position of the mouse at the time of this call to the function. These values can be negative.

NOTE: These return values ARE NOT the x,y coordinates of the mouse pointer on the screen!
(this gave me some grief early on hehe)

dbMouseMoveZ() is the mouse wheel (if you have one). (I use this value to zoom my camera in and out)

to turn the object based on mouse movement you can do this:


Hope you find this useful.

Regards,
Woozl

edit: typos, fix code
n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 28th Dec 2007 23:42
Well, since your screen is 2 dimensional, up would be Y+ down Y-, left X- and right X+.

tempicek
16
Years of Service
User Offline
Joined: 27th Nov 2007
Location: Prague
Posted: 28th Dec 2007 23:46
Sorry, I still can't get it.

What's wrong on this?



This should perform the rotation as you move with mouse.
Comp Guru 910
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location:
Posted: 29th Dec 2007 02:42
termpicek

it should be

if (dbMouseMoveX()) {
dbYRotateCamera (cameraid,dbmousemovex() * 0.02, dbCameraPostionZ(cameraid));
}
if (dbMouseMoveY()) {
dbPitchCameraDown (cameraid, dbmousemoveY());
}

But, im still having the same problem of when I put the code in




It only works if I move it up or down, and I have replaced where it says if (dbMouseMoveY()) with dbMouseMoveX and I still get the same reaction. It only works if I move the mouse up or down

typos...
Comp Guru 910
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location:
Posted: 29th Dec 2007 02:55
I fixed it, I had an error in some code

typos...
Codger
21
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 29th Dec 2007 03:11
Here a a modified version of the example "Game Level" that allows strafing in third person.

Use
up arrow key to move forward
down arrow key for reverse or back
left & right arrow key to straff

point the mouse where you want to go





Hope it helps

Codger

p.s. still need to add appropriate collision and terrain checks to anchor the player

System
PIV 2.8 MZ 512 Mem
FX 5600 256 mem
tempicek
16
Years of Service
User Offline
Joined: 27th Nov 2007
Location: Prague
Posted: 29th Dec 2007 16:47
Quote: "It only works if I move it up or down, and I have replaced where it says if (dbMouseMoveY()) with dbMouseMoveX and I still get the same reaction. It only works if I move the mouse up or down"


It seems to me that you are making it too complex (unnecessarily).
The code I've posted earlier does rotate the camera up and down or left and right accordingly to mouse movement (both horizontal and vertical). So I can't get what do you miss in there.
Comp Guru 910
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location:
Posted: 30th Dec 2007 02:29
Im sorry to make things overly complex. I just realized the other day that I did, lol. I had an error in my code that made so that if I moved my mouse up and down, it moved my camera left and right. I feel retarded lol. Anyways, I have that figured out now. if you know anything about file manipulation and reading, let me know

typos...
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 30th Dec 2007 03:52
Many of us could give you file manipulation pointers ... I'm sure of it. Make a new thread for that though bro so others looking for same kinda stuff will find it

P.S. Glad you got it worked out! It's very rewarding when you start navigating around your "world" the way you want to explore it

Login to post a reply

Server time is: 2024-11-17 00:08:48
Your offset time is: 2024-11-17 00:08:48