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.

Newcomers DBPro Corner / ATTENTION PLEASE!!! Movement in my game

Author
Message
Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 12th Feb 2006 20:13 Edited at: 12th Feb 2006 20:21
Hi all.
Ive got an idea for how I would like the movement to be in my 3d merchant game. The idea of the game is simple: You travel between planets and trade. The problem is that I came up with an idea about how to move the ship in a simple way, but Ive got no idea about how to do it. The idea is that when you want to travel to a planet, you dubbleclick on the planet (in the 3d space) with the mouse and then the ship will do the rest itself. It will turn until its facing the planet and then move to it. The tricky part is how to do it.

1. How do you make so the ship will know when its facing the planet?

2. How do you make so the ship turns in the right direction (if the planet is on its left side it turns left and if its on the right side it turns right)?

Thanks for your time.
SimSmall
20
Years of Service
User Offline
Joined: 7th Aug 2004
Location: United Kingdom
Posted: 12th Feb 2006 21:07
I can answer part 1:

I'll use "A" for your ship and "B" For the planet you want to look at...

after testing the double-click condition:

point object A,object position x(B),object position y(B),object position z(B)

alternatively, to make a smooth turn (instead of the instant turn as above)

test the double-click condition, and if true, set a variable. such as: turn = 1
and then...

if turn = 1
point object A,curveangle(object position x(B),camera angle x(),C),curveangle(object position y(B),camera angle y(),C),curveangle(object position z(B),camera angle z(),C)
endif

this needs to be part of a loop otherwise it will turn part of the way to the planet, then stop turning

C needs to be a whole number, try experimenting with this for yourself to get a turning speed you're happy with...
Yskonyn
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: Netherlands
Posted: 12th Feb 2006 23:58
Eventhough ___ was kind enough to help you on your way, I personally think it's quite rude to use caps in your topic title.
If you think you will gain attention by doing this, you might find yourself dissapointed in the long run, because people either start a flame or just ignore your post as a whole.

Good luck with your project, though.


Yskonyn - (Waiting for Hands On DBP Programming Vol. 1)
"It's better to wish down here you were up, then to wish up there you were down."
x1b
20
Years of Service
User Offline
Joined: 19th Sep 2004
Location:
Posted: 13th Feb 2006 01:32
I'm guessing that you dont get much attention at home. Thus the caps.

- Do it, Do it Right, Do it right now..
Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 13th Feb 2006 10:34 Edited at: 13th Feb 2006 11:14
Quote: "Eventhough ___ was kind enough to help you on your way, I personally think it's quite rude to use caps in your topic title.
If you think you will gain attention by doing this, you might find yourself dissapointed in the long run, because people either start a flame or just ignore your post as a whole."



Quote: "I'm guessing that you dont get much attention at home. Thus the caps."


Lol, only thought it might make people look threw the post. Didnt know it was considered rude. Guess I was wrong.
Chris Franklin
19
Years of Service
User Offline
Joined: 2nd Aug 2005
Location: UK
Posted: 13th Feb 2006 13:12
It's more considered shouting

Theme park simulator 15% Currently making object selection
Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 13th Feb 2006 18:28 Edited at: 13th Feb 2006 18:30
Ok, Ive tested it, but it doesent work. The ship turns instanly but I want it to when you dubbleclick I want it to turn smothly until its facing the planet, and then move to it. This is my code (I copies directly from ___´s post):



Why wont it turn as I want it to turn?


EDIT:

The command "colour" is a function I made so I could change the colour easier of 2d things, like texts, lines etc. Just remove it if it trubbles you.
SimSmall
20
Years of Service
User Offline
Joined: 7th Aug 2004
Location: United Kingdom
Posted: 13th Feb 2006 18:43
Sorry, the idea was untested, it may be that the number I had as C needs to be something like 30, or it may be that I've completely missed something out... If I see what I've missed, I'll post the mistake - but I am a little tired today...
Jerok
19
Years of Service
User Offline
Joined: 7th May 2005
Location: Mars. Wait a sec I\'m on MARS. OMG
Posted: 13th Feb 2006 19:20
this isnt too hard the simplest way i think to do this would be...
1. create a small object(sphere would be the easiest) and position it at the ships position.
2.point the object towards the selected planet
3.get the angle of the object
4.check if the x and y angles of the object are greater or less then the these angles of your ship
5.increase or decrease the angles of your ship slowly untill they match that of the object
6.check if the angles are the same if they are move the object toward the planet.

ill make and post an example soon

Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 13th Feb 2006 20:14
An example would be nice, but wouldt the angle that points the ship to the planet be relative to where the ship is? I mean, its a complete 3d game, so the movement take place in complete 3d.

Quote: "Sorry, the idea was untested, it may be that the number I had as C needs to be something like 30, or it may be that I've completely missed something out... If I see what I've missed, I'll post the mistake - but I am a little tired today... "


The highest nr I tested with was 70, same effect. Thanks anyway, you tried to help and I appriciate that.
Jerok
19
Years of Service
User Offline
Joined: 7th May 2005
Location: Mars. Wait a sec I\'m on MARS. OMG
Posted: 13th Feb 2006 20:30
ok some of the turns are a bit weird but it works you just click on the object you want to move toward if it doesnt work at first move the mouse and clikc a few more times because the mouse has to be very near the center of the object to go
heres the code


Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 15th Feb 2006 13:47 Edited at: 15th Feb 2006 13:49
Cant make it work . The ship just turns and never stops. Whats wrong?

Image All
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 15th Feb 2006 16:19 Edited at: 15th Feb 2006 16:22
Try this


FunkyStickmen: Battle of the Races (1%)
Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 15th Feb 2006 18:12
Didnt work.
Jerok
19
Years of Service
User Offline
Joined: 7th May 2005
Location: Mars. Wait a sec I\'m on MARS. OMG
Posted: 15th Feb 2006 18:14
Mr.X mine works fine i dont know whats wrong with yours you might have to global the angles as integers(im not sure why) but image all's is probably easier.

Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 15th Feb 2006 20:00 Edited at: 15th Feb 2006 20:06
I know it works just fine, Ive tested your example, and thats whats so weared. It should work. But for some reason I cant make it to. I can test to make them global as intrigers... if I can figure out how (still a noob).

Ive tried to make it work. Maybe its some other part of the subrutine, Ive both some code to control the "autopilot" and some to make a manual control system. Here it is:



Is there something wrong?


EDIT:

I just found a part that was wrong:

should be
. I fixed it, but it didnt work.
Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 16th Feb 2006 17:07 Edited at: 16th Feb 2006 17:13
Ok, Ive updated the code a little, and now it works much better. But not entierly. You see, the ship rotate until it has the right angle, and the moves, the only problem is that it does so in the wrong direction.



Why does it move in the wrong direction?

EDIT:

The angle of the "Guider" (check the code) doesent change even if you are on the other side of the planet. And then the ship moves in the "Guiders" direction.
Jerok
19
Years of Service
User Offline
Joined: 7th May 2005
Location: Mars. Wait a sec I\'m on MARS. OMG
Posted: 16th Feb 2006 18:55 Edited at: 16th Feb 2006 18:55
im sorry i dont know whats wrong with your code it might have to do with the angleship# and angleship2# stuff but i really dont know


what version of darkbasic are you using(dbc or dbpro)

Mr X
18
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 17th Feb 2006 16:52 Edited at: 17th Feb 2006 16:54
The problem wasnt your code, the problem was that I forgot to position the "Guider" at the ships position, so it would always be in the same location and thereby always look at the planets with the same angle. THATS was what the problem was, not your code. Thanks for helping me, I appriciate it.

EDIT:

And to answer your question, I use DarkBASIC Pro.

Login to post a reply

Server time is: 2024-09-24 15:38:44
Your offset time is: 2024-09-24 15:38:44