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.

Code Snippets / 3D lock on

Author
Message
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 14th Dec 2005 20:08
This is a function to lock something on from a 3D perspective, I couldn't handle locking it on from a 2D perspective.

Not only can this be used to lock something on, I personally would find it usefull to find the point I'm aiming at on an fps, and can also be used as an alternative to move object or move camera (though you would have to take away some stuff from it first).

One problem, I can't make it alter the x and Y coords. ONly the distance from the camera. Does anyone know how to get the inverse Sin and inverse Cos of something in DBPro?

Anyway, here's some code.

(Oh btw, you need to use the function in the main loop)



And the function:

Lock_On(object number,distance from camera)



Darkbasic MADPSP
19
Years of Service
User Offline
Joined: 15th Jun 2005
Location: Uk
Posted: 14th Dec 2005 20:17

Can't that do the shame job but nice code

Experienced DB http://www.greatgames3d.com (work in progress site)
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 14th Dec 2005 20:19
not really, notice I said that I didn't like doing it from a 2D perspective. i.e. once you've locked it on normally, when you move it it treats it like a 2d sprite on the screen, as you position it with 2d coords. With this it is positioned with 3d coordinates (well only the z one so far )

Darkbasic MADPSP
19
Years of Service
User Offline
Joined: 15th Jun 2005
Location: Uk
Posted: 14th Dec 2005 20:21
Quote: "LOCK OBJECT ON
This command will lock the specified 3D object to the screen. Locking objects to the screen commands the
object to completely ignore the camera's influence. A locked object will be positioned as though the
camera had never been altered from its default orientation. To make locked objects visible, simply set the
Z position to a significant positive value. The Object Number should be specified using an integer value.
"



Experienced DB http://www.greatgames3d.com (work in progress site)
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 14th Dec 2005 20:24
Yeah it will to the 3d screen, but it will have 2d coords.

Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 15th Dec 2005 18:23
Quote: "Does anyone know how to get the inverse Sin and inverse Cos of something in DBPro"

atan(), acos() and asin().

Immunity and Annihalation makes Immunihalation...
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 15th Dec 2005 19:37
oh.. oh yeah, thanks

Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 16th Dec 2005 14:03
np

Immunity and Annihalation makes Immunihalation...
Turoid
21
Years of Service
User Offline
Joined: 1st Nov 2003
Location: The Netherlands
Posted: 16th Dec 2005 22:47
Quote: "Can't that do the shame job but nice code"


It will do about the same job yes But if you are working with some lights in your map, and you use the lock object on command, the light doesn't affect the gun, with that function it does


.::Studying game design at the moment::.
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 26th Dec 2005 12:42
Hi,
this is another lock on function. The x,y problem is solved, you have to feed the values, of course:

Codelike
18
Years of Service
User Offline
Joined: 13th Dec 2005
Location: DBP - Scouseland
Posted: 16th Jan 2006 19:40
Here's another version with full x,y,z. No sin/cos is used. This uses keys.



I have an XP3000+, 1.5gb DDR333, a 6600GT and I'm programming 3k text-based exe's?!
Milkman
18
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 17th Jan 2006 00:01 Edited at: 17th Jan 2006 00:37
nice, but thats not what zotoaster meant by "3d lock on"... he meant to lock an object to the screen, such as a gun in an fps.

anyways, here is my function for doing so:

works with x, y, and z, and doesn't use sin/cos!
might be [slightly] slower than with sin and cos though

"Genius is 1% inspiration and 99% perspiration"
Uncle Sam
19
Years of Service
User Offline
Joined: 23rd Jul 2005
Location: West Coast, USA
Posted: 17th Jan 2006 00:11
Thanks Zoto! Can I use this?

--------------
Uncle Sam
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 17th Jan 2006 00:14
Sure thing

Codelike
18
Years of Service
User Offline
Joined: 13th Dec 2005
Location: DBP - Scouseland
Posted: 17th Jan 2006 03:43
Thanks xMik, I missed the point of that one! I was camera locking onto the 'character', rather then the 'gun', I think!
I hope someone can use it, though...

I have an XP3000+, 1.5gb DDR333, a 6600GT and I'm programming 3k text-based exe's?!

Login to post a reply

Server time is: 2024-11-23 07:43:59
Your offset time is: 2024-11-23 07:43:59