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 / object rotate in mouse direction problems!

Author
Message
WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 11th Dec 2013 14:43 Edited at: 11th Dec 2013 14:45
Hello
I am making a new game, temporary called BRUTAL SPACE. Brutal space is a top down 2.5D horror game I have recently started on. But I have get stucked into two problem so far. The problem is that I have difficulties to program a code that make so my player could turn/rotate in the mousecursor-directions. How could I been able to do that. Since I am a beginner I have also problems with to scroll the background, so if anyone have some tutorial/code examples on that, it would nice.

Here is my game code so far

This is my main file;



This is my gosub camera file;

Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 11th Dec 2013 18:51 Edited at: 11th Dec 2013 19:03
(Credited to a post by Chafari)



D.D.
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 11th Dec 2013 20:04
Hi there
Thanks Derek Darkly, but this code probably I took somewhere in the forum long long ago, when I start learning

This example is a bit more elaborated.




Cheers.

I'm not a grumpy grandpa
WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 11th Dec 2013 20:07 Edited at: 11th Dec 2013 20:27
@Derek Darkly and @chafari
I do not get your codes to work with my current code, I think you might have misunderstood what I mean, but that it's my fail (because of my bad english ).
That I mean is that I need a code that I could use to rotate my object in the directions of the mousecursor. Here is an example of a game that shows you what I mean http://www.youtube.com/watch?v=qSjnDKBLZbc. It could be a fail from my side when it regards the code, so if one of you could tell me how I could implement your code into my own code, that would be nice

thank both two for fast replies
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 11th Dec 2013 21:40
Ah, then you'll probably want to learn the PICK SCREEN command.

D.D.
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 11th Dec 2013 21:46
Quote: "Ah, then you'll probably want to learn the PICK SCREEN command."

Yes...this is the way, but I use a simple intersect to place a hiden object and force player go for it .




Cheers.

I'm not a grumpy grandpa
WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 12th Dec 2013 05:10
Thanks!
I will try out your examples as soon as possible
WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 14th Dec 2013 16:33 Edited at: 14th Dec 2013 18:41
Now I have tested your example chafari, and I think you have misunderstood my idea. Have you seen the link I posted above? My Idea is to make so the object turn/rotate in the mousecursor direction and NOT go towards, and following the mousecursor. I want it only to rotate/turn as it's in normal top down games. If you could help me with that it would be nice

Thanks for your reply chafari


Quote: "Ah, then you'll probably want to learn the PICK SCREEN command."


Derek Darkly could you explain more what the PICK SCREEN command does, and how I could use it?

Thanks guys for your fast replies
wattywatts
17
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 14th Dec 2013 21:20
Here's an example I found ages ago of the pick screen command. I've mostly used it to point bullets and stuff in shooters.



That said, if you're making a top down game it seems like it would be a lot easier to do this:



New sig coming soon..
WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 14th Dec 2013 23:14
Thanks wattywats

Quote: "That said, if you're making a top down game it seems like it would be a lot easier to do this:"


I think I will try to use your second example, because I think it would be a lot easier, than the method I am using for now.

But I have a question; have you any idea on how I could make a scrolling tile/background with the code-example you gave me above? Any examples or help would be very appreciated

Thanks again
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 14th Dec 2013 23:34
@waks if you just want the object point to mousecursor, just REM the line that moves the object...




I'm not a grumpy grandpa
WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 15th Dec 2013 08:48
Quote: "@waks if you just want the object point to mousecursor, just REM the line that moves the object...
"


I could try that

Thanks
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 15th Dec 2013 12:41 Edited at: 15th Dec 2013 12:44
Quote: "But I have a question; have you any idea on how I could make a scrolling tile/background with the code-example you gave me above?"


You could paste several sprite...



I'm not a grumpy grandpa
WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 15th Dec 2013 13:51
@chafari

Now I have tried out your code chafari, and I get an error on this two code-sentence;



Have you any idea of what the error could be? Without this sentences, the code works fine, but with a little bit stutter.

Thanks for your scrolling example
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 15th Dec 2013 13:57
Aahh!! Sorry , that is because you need matrix1 utils plugin that you can get free in this forum...I could do it again using original commands....let me know

I'm not a grumpy grandpa
WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 15th Dec 2013 14:09
Quote: "I could do it again using original commands....let me know"


Yeah, that would be nice since I am a beginner in Dark Basic Pro This is the first time I am programming a 3D game, and I have no experience with using cameras and objects commands before. I have only maked 2D games before this game, and hope working/experimenting with this game will give me a good foundation in 3D/camera commands

Thanks again for all your help
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 15th Dec 2013 14:25 Edited at: 15th Dec 2013 18:36
Ok ....now I'm having a relajante taza de cafe con leche....
Sorry I'm out with my smartphone in a coffee...

EDIT

In Darkbasic Clasic, we didn't have such a commands ...move camera left - move camera right....instead of that we use the newxvalue/newzvalue to place the camera on x,z



This code snippet above, is not complete, just to show what we use.

You can download this complete shooter tutorial with 25 lessons, that will show step by step how to make a shooter game. I hope you like it.

I'm not a grumpy grandpa
WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 15th Dec 2013 18:48
Quote: "I could do it again using original commands....let me know"


I figured it out self

But I have one problem. When I switch the camera view, the game become very jagged. Have you any suggestions about the problem? I have attached a video that shows the problem

Here is my do/loop or main game code;

chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 15th Dec 2013 21:08
I couldn't see your video as it report corrupt zip file. I don't know exaclty your problem as this is just part of yor code

I'm not a grumpy grandpa
WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 15th Dec 2013 22:06 Edited at: 15th Dec 2013 22:15
Quote: "I couldn't see your video as it report corrupt zip file"


Ok, I will try to fix that tomorrow

Quote: "I don't know exaclty your problem as this is just part of yor code
"


I give you the another code part tomorrow (because I have not time to do that right now)

Thank you for all your help!
WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 16th Dec 2013 21:35
@chafari

Now I have hopefully attached a working video file. NB! the jagged lines is not easy to see in the video, it's because of the video is compressed.

Here is also the part 1 of my code;



And here is the part 2 (included Source File);

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 16th Dec 2013 22:25
Wait! So you want to make a top down game where the camera rotate with the player and the player rotates based on the mouse position. But you can also switch to the camera following the player?

I ask so we can best help. If you can exactly how you want it to function and supply examples if you can then that would help greatly

You posted and example of Darkwood which showed player rotation based on the mouse. But your latest vid the whole camera is rotating also. So I'm not sure which you want. Hence why I ask.

"Get in the Van!" - Van B
WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 16th Dec 2013 23:00 Edited at: 16th Dec 2013 23:01
Thanks Sasuke!

Quote: "You posted and example of Darkwood which showed player rotation based on the mouse. But your latest vid the whole camera is rotating also. So I'm not sure which you want. Hence why I ask."


Yeah that was my first idea, until chafari was showing me an example. After a while I started to experimenting with his code (because it was very easy to understand), as the end result was what you see in the video (see above)

If you have some comments or improvements on this code or an antoher code, it would be nice
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 17th Dec 2013 02:17 Edited at: 17th Dec 2013 10:50
Quote: "Yeah that was my first idea, until chafari was showing me an example. After a while I started to experimenting with his code (because it was very easy to understand), as the end result was what you see in the video (see above)"


Ahh yeah, now I understand. That game EDIT(DOES) look interesting though so cheers for sharing

Quote: "If you have some comments or improvements on this code or an antoher code, it would be nice
"

Firstly indentation is key, it's makes your code tidy and clean and easier to look through. Commenting and name variables correctly helps as well in those debugging process.

I wrote an example of what I'm talking about based off your code and fixed that issue you was having. Though I excluded object 2 cause I didn't know what it was doing:


"Get in the Van!" - Van B
WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 17th Dec 2013 07:31
Quote: "That game doesn't look interesting though so cheers for sharing"


Yeah the game is not finished yet, and all the models and textures that you could see in the video is just for test. So the video I posted above was only to illustrate the basic movement/camera in the game.

Quote: "Firstly indentation is key, it's makes your code tidy and clean and easier to look through. Commenting and name variables correctly helps as well in those debugging process."


Thanks for the example you gave me. I will try to clean (with indentation) up my game code, so it become more easier to read/debug.

But I have a question, will the example you gave me get rid of the jagged lines ( especially in the 3D view)?

Thanks for fast reply!
WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 17th Dec 2013 07:32
Quote: "That game doesn\'t look interesting though so cheers for sharing."


Yeah the game is not finished yet, and all the models and textures that you could see in the video is just for test. So the video I posted above was only to illustrate the basic movement/camera in the game.

Quote: "Firstly indentation is key, it\'s makes your code tidy and clean and easier to look through. Commenting and name variables correctly helps as well in those debugging process."


Thanks for the example you gave me. I will try to clean (with indentation) up my game code, so it become more easier to read/debug.

But I have a question, will the example you gave me get rid of the jagged lines ( especially in the 3D view)?

Thanks for fast reply!
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 17th Dec 2013 11:06 Edited at: 17th Dec 2013 11:06
Quote: "That game doesn't look interesting though so cheers for sharing"


Whoops!!!! That came out wrong. Sorry for the mistake. It should be 'That game does look...' and I was talking about 'Darkwood pre-alpha gameplay'! At the moment your game is far to early in development to judge.

Quote: "But I have a question, will the example you gave me get rid of the jagged lines ( especially in the 3D view)?"


The Jagged lines is bases on your resolution which I noted in the example at the top that maximize window just stretches the window to fit the screen but doesn't change the resolution of your game. Either do this through the IDE (dbp editor) or use Set Display Mode command to set your resolution.

"Get in the Van!" - Van B
WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 17th Dec 2013 19:50 Edited at: 17th Dec 2013 20:07
Quote: "Whoops!!!! That came out wrong. Sorry for the mistake"


No problem, that's okay. I understood what you mean

Quote: "The Jagged lines is bases on your resolution which I noted in the example at the top that maximize window just stretches the window to fit the screen but doesn't change the resolution of your game. Either do this through the IDE (dbp editor) or use Set Display Mode command to set your resolution"


Ok, but how could I make the game so it fit every screen it runs on (In full screen mode) without all the jagged lines? It's possible to scan the screen resolution before the games run, so it could run the game in full screen mode?

One more question; is it wrong to use the create animated sprite command instead of load image command, because my game run 2x faster with the create animated sprite command
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 17th Dec 2013 20:09 Edited at: 17th Dec 2013 20:16
Quote: "Ok, but how could I make the game so it fit every screen it runs on (In full screen mode) without all the jagged lines? It's possible to scan the screen resolution before the games run, so it could run the game in full screen mode?"


There are a couple of ways. Simplest is to use Desktop Width/Height commands or Ian M's matrix plugin (absolutely get it! It's a must for DBP) Display Width/Height Use it like this:


Though I'm still not sure which is the correct mode for fullscreen because it seems depended to the IDE your using. For instance CodeSurge has Fullscreen and Windowed Fullscreen. The final result is the same expect they seem to function differently on different computers. That one is a guess really. But the IDE graphic mode or screen type does affect how the display commands work. I would just experiment to see which works best for you.

"Get in the Van!" - Van B

Login to post a reply

Server time is: 2026-07-06 11:22:44
Your offset time is: 2026-07-06 11:22:44