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 / having a object in front of you while moving, need help!

Author
Message
sovr
16
Years of Service
User Offline
Joined: 2nd Jan 2010
Location: USA
Posted: 15th Apr 2012 23:08
ok I just am not getting the correct math to complete this task. I know you need to use sin and cos to do this, but I am asking what is the correct math to have an object always in front of you when you move and turn?

this is what I thought would have worked: position object(obj,sin(camera position x()),y,cos(camera position z())

*when I do this, the object just stays in one spot, thank you everyone for your help!

sov the game creator!
Dar13
18
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 15th Apr 2012 23:25
You have to use the camera angles, not the positions, and add the results of the sin/cos to the position of the camera.

So it'd look something like this:
position object obj,camera position x() + cos(camera angle y(0))*5,y,camera position z() + sin(camera angle y(0)*5
disclaimer: this is off the top of my head, probably won't work.

basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 15th Apr 2012 23:50
why don't you lock the object to the camera or object to object, that would be much easier.

however, if you intend to use mathematics. there is a better solution using vectors.

exp: if the 3d vector of your object or camera is: Ax+By+Cz then the object will be distance*(Ax+By+Cz)

summary:


another way using matrix.
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 16th Apr 2012 03:46 Edited at: 16th Apr 2012 04:18
all right, I had to get home to do the explanation for you. here is a code example.



now, the command "lock object on objno" does not actually keep the object (in the example sphere) at relative position from the camera but, it stick the object on the screen and it looks as moving with the camera.

if you're looking for more complicated position/rotation calculations, I suggest using EZ rotate. it's such an amazing pluggin and I used it for major delivered projects.

http://www.thegamecreators.com/?m=view_product&id=2082
Millenium7
21
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 16th Apr 2012 08:08
it's been a while since i've had to do this, however what exactly is wrong with the newxvalue, newzvalue commands? This is what I was taught with DB classic and it works perfectly and allows you to specify a 'distance' between objects. I use this for both camera and objects. No such silly nonsense as 'locking' an object to another, do it by hand
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 16th Apr 2012 11:09 Edited at: 16th Apr 2012 11:11
Easiest solution if you don't want to worry about maths is:



If you want the object offset slightly left/right or up/down, just add:


People may argue that's not as fast as using vectors or trig, but it's plenty fast enough and easy.

basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 16th Apr 2012 18:39
There are plenty if solutions for this problem. Even another solution is to glue object to limb to limb 0. And many others.
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 16th Apr 2012 19:29 Edited at: 16th Apr 2012 19:32
here is a way without any math:
the trick is to move the object to the camera position, then move the offset a little bit.
do that every frame.



edit: just noticed Fallout wrote the same method already.. oh well

more 3d models .x/.obj and more foramts here:
[href]https://www.turbosquid.com/Search/Index.cfm?keyword=gogetax1&x=0&y=0[href]
MadBit
VIP Member
Gold Codemaster
17
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 17th Apr 2012 09:29
Quote: "if you're looking for more complicated position/rotation calculations, I suggest using EZ rotate. it's such an amazing pluggin and I used it for major delivered projects."


If you want a free version of EZ-Rotate. Then take a look at my eXtendet-Rotation plugin. I think this can save some work in evry project with complex position and rotation math's.

eXtendet-Rotation

With Computers you can solve Problems that you have never befor.
Share your knowledge. It's a way to achieve immortality. (Tenzin Gyatso)

Login to post a reply

Server time is: 2026-07-09 01:51:19
Your offset time is: 2026-07-09 01:51:19