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 / Missile rotates the longest route

Author
Message
Maelstrom
20
Years of Service
User Offline
Joined: 24th Feb 2004
Location: United Kingdom
Posted: 11th Mar 2004 23:26
After looking through this forum for tips i've tried to put into practice what i have learned. Here is my code in which you control a square around the screen. Use left/right to rotate and up/down to speedup/slow down. When you hit spacebar the cylinder is suppose to home in on the square;which it does.

Question:

All works well but at certain points the cylinder rotates the long way round. I can understand why it does it, but i've got brain block trying to fix it. Could someone have a look at the code and give me a little advice please. I've put *** around where the problem code is.

Also

1. Am i right in thinking that this is using vectors. If so, would this code benifit with the built-in vector commands. Tips on this please as i haven't got to grips with these commands yet.

2. When i'm moving the square around it would be good to get some type of skid effect.

3. Any other advice on the general code would be great.

Thanks in advance
Maelstrom
20
Years of Service
User Offline
Joined: 24th Feb 2004
Location: United Kingdom
Posted: 11th Mar 2004 23:28
Maelstrom
20
Years of Service
User Offline
Joined: 24th Feb 2004
Location: United Kingdom
Posted: 13th Mar 2004 18:31
I'm a little disapointed that i didn't get any response. Maybe i'm just being to impatient. Anyway, after spending ages looking at other peices of code on this forum i've eventually fixed my own problem. Learned a few new commands on the way also. So if anyone's interested here is the fix. Answers to any of my other questions though would still be appreciated.

[u]REPLACE
rem ***********************************************
if zangle#>totalangle# then zangle#=zangle#-3
if zangle#<totalangle# then zangle#=zangle#+3
rem ***********************************************
zangle#=wrapvalue(zangle#)
xmispos#=xmispos#+misspeed#*sin(zangle#)
zmispos#=zmispos#+misspeed#*cos(zangle#)
yrotate object 2,zangle#
position object 2,xmispos#,0,zmispos#

WITH

zangle#=curveangle(object angle y(2),totalangle#,2)
yrotate object 2,zangle#
xmispos#=newxvalue(xmispos#,zangle#,misspeed#)
zmispos#=newzvalue(zmispos#,zangle#,misspeed#)
position object 2,xmispos#,0,zmispos#
endif
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 14th Mar 2004 18:04 Edited at: 14th Mar 2004 18:05
@Maelstrom

I've just had a look at your code, and the replacement you've posted above. Its good that you've solved your own problem. I always say that trial and error are by far the best ways of learning.

Anyway, answering your questions:

1. Your code uses trig and not vector math. You can achieve what you have done using vector math and DBPro's built in commands. However, if you are operating only in two dimensions (I see your objects are on the X/Z plane) then its probably not necessary to use vectors. I'd always recommend vectors when operating in three dimensions though.

2. This can be achieved using trig or vector maths. See the code snippet recently posted by Dennuz http://darkbasicpro.thegamecreators.com/?m=forum_view&t=27545&b=6 for an example of how to achieve it with trig.

3. Its nicely presented. I also like the fact that you have indented it. This is important in my view. Too many people don't indent their code and then its a nightmare to read.

Please can you think about posting your code into both the code snippets and codebase. I read requests on here for so-called "homing code" from time to time. If your code is posted into the archives other people can learn from it.

I hope this is helpful.

Philip

What do you mean, bears aren't supposed to wear hats and a tie? P1.3ghz / 384 megs / GeForce MX 5200 128meg / WinXP home
Maelstrom
20
Years of Service
User Offline
Joined: 24th Feb 2004
Location: United Kingdom
Posted: 14th Mar 2004 18:39
Philip

Thanks for the constructive comments. I had a look at the code snippet and gleaned a little extra knowledge which no doubt i will put to good use later on.

Although i did manage to fix my own problem the real excercise was to fix an issue i'm having in my other post "FPS - where do the bullets go". I though if i could achieve this then i wouldn't be too far behind the other. I'm not sure though that even armed with my new commands that i'm on the right track. Maybe if you have time you could take a look at that post.

Thank's Again

Login to post a reply

Server time is: 2024-11-26 07:30:06
Your offset time is: 2024-11-26 07:30:06