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 / Intercept Target

Author
Message
XFS Illusion
18
Years of Service
User Offline
Joined: 20th Apr 2006
Location:
Posted: 30th Oct 2007 22:32
Have a space flight sim, When a target/object is selected(12 for example) and letter 'I' is pressed, I want my ship to turn towards the target at it's present speed until i let off the "I" key. I have it working using the following simple code, but it jumps too sharply towards the target. Object 10 is my target, 12 is the target i'm closing in on.



If possible I would like it to bank/tilt and turn at the same rate it does when I navigate manually, but i'm not clear on how to do this exactly since there are unknowns. Here is the code I use to manually navigate my ship...



I figure I can use the same code If i can just figure out how to implement it into the intercept sub. Basically, when the I key is held, it will act as an autopilot while my ship heads towards the target. After i figure this out, i'll fix it to where i wont have to hold down I, that it will follow until it reaches it, then match it's course and speed until i change my target.

Any suggestions anyone? Thanks in advance.

XFS Illusion
18
Years of Service
User Offline
Joined: 20th Apr 2006
Location:
Posted: 31st Oct 2007 06:09 Edited at: 31st Oct 2007 20:56
How easily something goes unnoticed in these forums. Not to mention, searching aint too good either, the search engine seems to have a problem with multiple keywords. I get one message that says over 100 results were found, and to narrow my search, but right below it says no results found...go figure. Not sure if it's how i'm searching, or just the way it is but oh well.

Zergei
19
Years of Service
User Offline
Joined: 9th Feb 2005
Location: Everywhere
Posted: 31st Oct 2007 12:59 Edited at: 31st Oct 2007 13:01
What i do when coding movement functions and such, establish variables to the conditions instead of a direct comparison with keystates. Something along the lines like this...



This way, if i need to move via my code, all i gotta do is set "left" or "rigth".



However, in your case, you've got a common function going on there, which is, intercept and other stuff. For this you could create a sepparate function, without using your current movement code. This, actually, is not the "recommended" way.

Personally, i would first set the movement calculation into a function so that i could call it from wherever i need it to move something. Not only your ship(?) but also your enemies ship, and many other things that involve moving.

This is quite a quick post i've made, since in 2 min i gotta got to work. If needed i can explain further and suplant some code. But i advice you tey to figure it out first.

If in doubt, ask.

Further on my stuff at...
TurboSquid.com
The3dStudio.com
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 31st Oct 2007 19:21
@XFS Illusion - Yeah - Zergei raises a good point.

Back up a little. The way I make my Vehicles - is that I don't manipulate them in the GAME's main logic - via manipulating the 3d etc. I make functions for doing certain tasks - handle all of it.

For Iron Infantry - Tanks for example have an array of type that looks like:



The point is my game code, Ai Code, User Input routines etc, Only modify the above type's booleans - could be integers and floats to - like how much throttle, how much left etc. if you want. By doing this - you now can "Drive" your vehicle exaclty the same way - whether from userinput or AI just by setting the flags how you want - and when the UPDATETANKS routine is called or whatever - they are all processed the same way regardless if from the USER INPUT - keyboard, joystick... or from AI.

In MY AI routines - I would still reference objects - to get measure ments, bad guy's bearings or whatever - but CONTROLLING the vehicle would be done the way I describe - then all the vehicles are going through the same logic regardless who is driving

Now for the Whole intercept bearing thing - there is probably some majic trigonometry formula - but if you want your AI to work like how you would intercept a bearing - than try to nail down the logic you do instinctivly in code! Like - do you roll your so the enemy seems to be going "UP" the sccreen so you can pull back on the joystick and follow like that? (That's what I do usually) think about how you could write code to mimic this or other strategies. You might its less "eratic" and more "human" looking after putting some work into it. Calculating bearings for a tradjectory shot though - that takes some math - period - and even then just gets you close unless NO ONE changes tradjectory or something from the time the calc happed until the bullet/laser whatever hits its mark.

XFS Illusion
18
Years of Service
User Offline
Joined: 20th Apr 2006
Location:
Posted: 31st Oct 2007 21:03 Edited at: 31st Oct 2007 21:28
Converting my code to a function would be pretty easy, considering i currently call it with gosub statements...still not sure how to implement this though. I mean, for example the point object statement, if i indeed use that statement...how can i slow it down so that the ship actually has time to curve left or right? Is point the wrong command since it tends to want to jump right to the object? I'm thinking that I need to use another method of pointing towards the targeted ship. Anyway, I know i have alot to learn about DBP, i do alot with trial and error(after error, after error)...I can set up the functions and it is in fact a good idea to do so...still not sure about the AI though. Maybe I need a command or function that can tell me if i'm pointed at an object or not...is there any such command? Just wondering. This way, i can swing it left, right, up or down until it's pointed...hard to explain. Note that this is a Multiplayer Game, so AI is limited really since my enemies will be other real players.

EDIT: For some reason, when I attempt to implement this into a function it doesn't bank correctly and it sticks to the bank. This was a function when i first started coding this, i made it the way it is now for this reason. Not sure why it doesn't work well as a function, seems like it does the exact same thing...this is why i changed it from a function to a sub before.




Michael Jackson
16
Years of Service
User Offline
Joined: 31st Oct 2007
Location: Paris
Posted: 31st Oct 2007 21:26 Edited at: 5th Nov 2007 01:29
hello, are you going to make a kind of StarWraith ? this what I dream to do, one day maybe. I read your post, I can see & resolve the problem, in your snippet:
"Intercept:
point object 10,object position x(12),object position y(12),object position z(12)
endif
return "
I can read "Endif" but where is the "If" ?. so easy to fix!


jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 31st Oct 2007 21:46
Well - if you use variables in a function that are not global - they only LIVE in that function. This could be your problem.

The good thing is in a function if you make a temp variable - it REALLY is a temp variable.

So - for VARIABLES you want to use in a function - make them global!

GLOBAL plyr_tilt#

XFS Illusion
18
Years of Service
User Offline
Joined: 20th Apr 2006
Location:
Posted: 31st Oct 2007 22:05
Making it global worked, had to write a reset function to reset the ship's rotation once I let off the keys, but it seems to work. I think i'm going to need some help and/or more detailed examples when it comes to the AI autopilot for the intercept.

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 1st Nov 2007 00:10
I am not the AI expert - In fact - I question my biological Intelligence often - so I'm simply not a great canidate here - basically - I will be doing a ton of the same thing you are now forced to when I get that far in Iron Infantry. Note DarkPhysics I THOUGHT had AI as well - maybe its a separate product - point is I might use a tool like that - not sure yet.

Very rewarding to see you'er own AI code work.

Point Object I WOULD THINK would useful PROVIDING you used a dummy object - then by looking at the coords of the dummy object after using point object on it - you should be able to discern if your spaceship should turn left, or right, up or down. this will be a pain in the rump because Elar angles are not as simple as 0-359 degrees per plain... And I hate how just the slightest "pivot" can make the Z plain flip to -180 and ... well - you'll see eular can be a pain when it comes to this kind of stuff.

I THINK this is where EZ_ROTATE shines. I bet you could use that to get simpler answers to your questions like - Should I Turn up or down etc - might be easier if the point object thing is a nice even number rto the left, etc.

If object angle x(DummyObj) > object angle x(MyShip) then TurnShipLeft(MyShip)

Good Luck

Zergei
19
Years of Service
User Offline
Joined: 9th Feb 2005
Location: Everywhere
Posted: 1st Nov 2007 12:59
Right now im working on an intercept function. Once i get it working i'll show it and explain it, of course.

Further on my stuff at...
TurboSquid.com
The3dStudio.com

Login to post a reply

Server time is: 2024-09-27 08:35:08
Your offset time is: 2024-09-27 08:35:08