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.

DarkBASIC Professional Discussion / first person sword game

Author
Message
steve123
20
Years of Service
User Offline
Joined: 30th Nov 2004
Location:
Posted: 20th Dec 2004 18:29
i would like to make a game where you around killing things but i want to make the sword so that when you move your mouse across the sceen the object sword will move with it and depending on the speed in wicth you move the mouse the more damage you will cause if you hit a enemy.
so can someone help me with this
Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 20th Dec 2004 18:39
There is a Code Snippet example of this, should check it out


Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 20th Dec 2004 18:40
There is a topic like this in the game design forum, Uberwigget was/is working on a sword fighting game, you might get some pointers there.


Van-B


It's c**p being the only coder in the village.
Lost in Thought
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 20th Dec 2004 18:43
steve123
20
Years of Service
User Offline
Joined: 30th Nov 2004
Location:
Posted: 20th Dec 2004 22:04
thanks for the code snippets but i really what to know how make a sword go across the screen when you move the mouse across the screen

im using the four arrow keys to move left/right rotate the camera.
i just need to how to keep the object sword in front of the camera and how to make the sword object follow the mouse direction and is there a way of detecting the speed of the mouse.
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 20th Dec 2004 23:55
Mousemovex() and Mousemovey().

If you lock an object to the screen, you can then position it in relation to the screen - so you might lock a sword, then position it so it shows at the right hand side (like positioning it at 10,5,5). With it locked and positioned, you can simply rotate the object how you like. I'd go for an animated model instead of pure mouse control though, like animated swings but carried out with the mouse. For example moving the mouse to the top of the screen then clicking and dragging the mouse down quickly might perform a slash move, but moving the mouse to the bottom and clicking then push the mouse forward might indicate a stab move.


Van-B


It's c**p being the only coder in the village.
Wiggett
21
Years of Service
User Offline
Joined: 31st May 2003
Location: Australia
Posted: 21st Dec 2004 00:12 Edited at: 21st Dec 2004 00:20
Please continue with your animated models idea already!

Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 21st Dec 2004 00:24
Why of course Rob...



One day I'll make you a demo and proove that animated arms are worthy enough to hold weapons of might.


Van-B


It's c**p being the only coder in the village.
steve123
20
Years of Service
User Offline
Joined: 30th Nov 2004
Location:
Posted: 21st Dec 2004 00:35
ok i manged to get the object and the mouse moving togther but how do i get the object to turn and move with the camera
steve123
20
Years of Service
User Offline
Joined: 30th Nov 2004
Location:
Posted: 21st Dec 2004 00:54
ok maybe i the mouse thing is not working as i hope can some one plaese give me a example or somthing i getting stuck quick
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 21st Dec 2004 01:28
Yup, if you follow the links you shall find a code snippet,LIT posted them already .


Van-B


It's c**p being the only coder in the village.
steve123
20
Years of Service
User Offline
Joined: 30th Nov 2004
Location:
Posted: 21st Dec 2004 21:47
i tryed modifying the code snippet to what i whated it to do but it will not work when i move the mouse the object flies of the screen and it wont comeback can someone please just tell my how to make a object follow the mouse and stay in the cameras view even when turning and moving forwards and backwards
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 21st Dec 2004 22:32
Ahh, that code does'nt lock the object to the screen - sorry, I thought it was a first person type demo.

The comman LOCK OBJECT ON will lock an object to the screen, then positioning it is in relation to your screen, once you get it positioned where you like, rotating it should simply rotate it on it's pivot point.


Van-B


It's c**p being the only coder in the village.
steve123
20
Years of Service
User Offline
Joined: 30th Nov 2004
Location:
Posted: 22nd Dec 2004 00:08
Thanks Van B that work, when i turned the camrea the object stays in view. My next qusetion is about the mouse. The object move with the mouse but there are some errors when i move the mouse down the object goes up and when i move the mouse right the object goes of the screen and mouse has not gone all the way to the edge of the screen its nearer to the left side of the screen. The object is to senstive to the mouse or somthing like can anyone help i cant work out why the object acts like this.
steve123
20
Years of Service
User Offline
Joined: 30th Nov 2004
Location:
Posted: 22nd Dec 2004 01:04
in the code snippet this is what i have come up with and maybe help you to understnd whats going wrong.
you have to put the the cusor near the uper left coner of the srceen to see the object.
the dirction of the sword is working now up on the mouse makes the object move up its just i cant get the object to stay in view when the mouse goes towards the bottom rigth corner please help.
steve123
20
Years of Service
User Offline
Joined: 30th Nov 2004
Location:
Posted: 22nd Dec 2004 01:05
REM MAKE MATRIX
MAKE MATRIX 1,1000,1000,10,10
REM MAKEOBJECT BOX(SWORD)
MAKE OBJECT BOX 1,5,20,1
ZROTATE OBJECT 1,30
XROTATE OBJECT 1,20
REM POSITION CAMERA
PITCH CAMERA UP 10
POSITION CAMERA 0,50,0
REM LOOP
DO
REM CONTROL OBJECT(SWORD)
LOCK OBJECT ON 1
POSITION OBJECT 1,MOUSEX()-40,-MOUSEY()+60,40
REM CONTROL CAMERA
IF UPKEY ()=1 THEN MOVE CAMERA 0.7
IF DOWNKEY ()=1 THEN MOVE CAMERA -0.5
IF LEFTKEY()=1 THEN TURN CAMERA LEFT 0.4
IF RIGHTKEY ()=1 THEN TURN CAMERA right 0.4
IF CONTROLKEY ()=1 AND UPKEY ()=1 THEN MOVE CAMERA 1.3
LOOP
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 22nd Dec 2004 01:17
Something like this:



Note that I added sync controls, and changed the mouse handling so it's all in variables which are changed according to the mouse movements rather than position. Also the mouse is limited to keep the weapon in screen, you can experiment with the values quite easily as it displays them as well - you'd just rem out the checks at the start of the code to work out your own limits.


Van-B


It's c**p being the only coder in the village.
steve123
20
Years of Service
User Offline
Joined: 30th Nov 2004
Location:
Posted: 22nd Dec 2004 01:25
thank you so very much its just want i wanted to happen i think this is my last qustion is there a way to measure the mouse speed i want to know cos i what it so the more speed you put the mouse the more damge it will inflict on the enemy

thanx for all your help van b
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 22nd Dec 2004 01:40
I suggest storing the mousemove variables if you want to check them more than once in the main loop. Like:

MMX=mousemovex()

Then the variable MMX will contain the speed of the mouse X movement in pixels - however, this might not be too accurate if your frame rates are jittery (which is often out of your control). So, I suggest using a more complex measuring system, like:

MMX=mousemovex()
MMY=mousemovey()
if MXSPEED#<MMX then MXSPEED#=MMX else dec MXSPEED#,0.1
if MYSPEED#<MMY then MYSPEED#=MMY else dec MYSPEED#,0.1

So if you move really sharply then stop there's no chance of loosing track of the intended speed. If you also check for when both speed variables are <=0 - that would be a good time to set the weapon back to where it should be on the screen.


Van-B


It's c**p being the only coder in the village.
steve123
20
Years of Service
User Offline
Joined: 30th Nov 2004
Location:
Posted: 22nd Dec 2004 19:28 Edited at: 22nd Dec 2004 20:11
now there is a new problem i made a cube as a enemey but i cant get the collsion to work i put if object collsion (1,2) then delete object 2 when tested it nothing happed am i using the wrong code or have i missed somthing.
HELP!

p.s. i could not get the mouse speed thing to work van b
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 22nd Dec 2004 20:17
I'll see what I can come up with tonight, at work just now .


Van-B


It's c**p being the only coder in the village.

Login to post a reply

Server time is: 2025-05-29 05:46:21
Your offset time is: 2025-05-29 05:46:21