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 / Object positioning

Author
Message
Justice
19
Years of Service
User Offline
Joined: 22nd Jun 2004
Location:
Posted: 27th Jan 2015 21:57 Edited at: 27th Jan 2015 21:58
Hi,

Im sure this is a really easy problem to fix.

I have created a 3d world and im moving around it.

position object player,object position x(player),ypos,object position z(player)

I want to place an object just in front of my character, so when I move around it keeps just in front of me.


How do I do this, if I add a number to the x or z position it will place the object to the right or left depending on how I move.

position object new_object,object position x(player),ypos,object position z(player).

I now im missing something really simple !!
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 28th Jan 2015 01:12
Give the object the same position and orientation of the camera or player then move the object forward the distance you want to place it.
Justice
19
Years of Service
User Offline
Joined: 22nd Jun 2004
Location:
Posted: 28th Jan 2015 07:53
Thank you, ill try out your suggestion.
Scorpyo
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 28th Jan 2015 10:10
objx#=newxvalue(object position x(player),object angle y(player),offset)
objz#=newzvalue(object position z(player),object angle y(player),offset)
position object objnum objx#,ypos,objz#
yrotate object objnum,object angle y(player)

if offset is positive the object will be ahead of the player
if offset is negative the object will be behind the player


example:

Justice
19
Years of Service
User Offline
Joined: 22nd Jun 2004
Location:
Posted: 28th Jan 2015 15:50
Thankyou very much for your help.
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 29th Jan 2015 01:35 Edited at: 29th Jan 2015 01:36
Nice routine. Don’t got me wrong, I love math. But, wouldn’t it all be the same if you replaced this:



With this:



Less code, less math.
Scorpyo
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 29th Jan 2015 10:56
Your comment is welcome and absolutely right in relation to the result.
if you like math, the same result can be had with:

x1#=x#+cos(angle#+90.0)*-distance
z1#=z#+sin(angle#+90.0)*distance
position object 11,x1#,h#+10,z1#
yrotate object 11,angle#

I think it's a matter of coding style.
I prefer more "verbose" coding based on more variables available for tweaking .
Notice that adding an offset to:
yrotate object 11,angle# you can rotate the object at will by manipulating the offset.

here's a refined version of the previous post code:



Cheers
Scorpyo
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 31st Jan 2015 22:20
Cool! I like this code. I have saved this for future reference. May use this, if it's ok with you?

Thanks.
Scorpyo
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 1st Feb 2015 11:13
No problem at all.
You can use , refer to, modify any code I do post here.
Cheers
Scorpyo

Login to post a reply

Server time is: 2024-03-28 16:19:32
Your offset time is: 2024-03-28 16:19:32