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 / Keeping an object with the camera

Author
Message
Disrupter52
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 26th Jul 2011 20:27
Hey everyone

So i made 2 weapons that i want to pick up and have stay on-screen in my game. I got the picking up part working, but i cant quite get the staying part.

I want my weapons to stay on the right side of the screen a little in front of the player, like they were holding it. I cant get the object to stay when the camera rotates though, im not sure how to go about doing that.

thanks
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 26th Jul 2011 21:20
Have a look to command lock object on

Cheers.

I'm not a grumpy grandpa
Disrupter52
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 29th Jul 2011 04:54
Yea, ive tried that and the object moves around nonsensically. Idk how to work it properly to have it do what i want.

right now when i try it, the object is only where it should be at the origin and as i move, the coordinates are where they should be (i have my coords and the objects print) and it says its always at the same z and +5 on the x (which is how i coded it) but the farther i move from 0,0 (i dont move on the y ignore it.) the more it like scales out of view til it disappears.
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 29th Jul 2011 12:26 Edited at: 29th Jul 2011 12:27
Try this piece of code. You can change the gun for yours.





Cheers.

I'm not a grumpy grandpa
Disrupter52
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 2nd Aug 2011 07:29
Ok after much struggling, it doesnt help.

Im trying to make an axe basically sit right in front of the right side of the screen. Period. No matter where im looking.

set object to camera doesnt help, neither does locking it.

i also need it to work at a key press.

I can envision the camera being a point in space. The axe is based on another point that needs to revolve around the camera in a sphere essentially, but never moving closer or further from the camera.

Ultimately, ill have a model holding the axe and i guess that would be easier then what im doing, but i wanted to experiment with picking up objects and having them float around but apparently thats really complicated.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 2nd Aug 2011 16:06
Have you tried something like this: (only pseudo code)

Is this is done after each camera update then your object will be in the same position.

Warning! May contain Nuts!
Disrupter52
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 3rd Aug 2011 04:20
I tried fiddling around with some of that code, it doesnt work the way i need it too. The rotate object based on the camera rotates the object, but it doest rotate it around the fixed point of the camera, it rotates it around the object according to the camera's angles.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 3rd Aug 2011 05:25
I kinda understand what you mean. You can set the rotation something like this:

Rotate Object my_axe, Object Angle X( main_obj ), Camera Angle Y(), Object Angle Z( main_obj )

That way you're using the X and Z from the object but the cameras Y angle.

You might need to mix and match some of these for other objects.

Hope this helps...

Warning! May contain Nuts!
Dar13
18
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 3rd Aug 2011 05:28 Edited at: 3rd Aug 2011 05:33
Here's some code I ripped straight from my current project.
What it does is that it creates a player object(a .1 radius sphere at [0,0,0] at [0,0,0] rotation). Then it adds a limb(tiny triangle) at a position [1,0,4] offset from the player(just in front of and to the right) and rotates it 180 degrees(you may/may not need this). That's all in the first snippet.

In the second snippet, simply shows how you 'attach' a weapon(in your case an axe instead of a gun) by using the 'glue object to limb' command.

The third snippet shows how you update the original player object in order to keep limb your weapon is glued to in the view of the camera.

I realize that this is a bit complicated for what you might see as a simple task, but I had the same problem and this is my solution.

Note: The first and second snippet only need to called once(unless you use multiple weapons, in that case use the second snippet as needed). The third snippet needs to be called every loop or every time the camera changes position.







Note about the snippets: These are literally ripped straight from my game. They will not work by just copying and pasting, you will have to adapt them to your program. If I can find the original snippet I got this idea from I'll link it here.

EDIT: Here's a more generic snippet:http://forum.thegamecreators.com/?m=forum_view&t=150776&b=1&msg=1758398#m1758398

Login to post a reply

Server time is: 2026-07-11 08:47:03
Your offset time is: 2026-07-11 08:47:03