Jump to content

[SOLVED] placing objects in front of you


AggrorJorn
 Share

Recommended Posts

I'm working on my "picking up objects" code but I am facing a problem. I can pick up the object but the positioning of the object is not working correctly. The object is being placed by using the camera position plus 2 more in the z axis. However, since the axis of the camera doesn't rotate, the object is always placed in the wrong place:

if pick.entity~=nil then
				pickedUpEntity = pick.entity
				pickedUpEntity:SetPosition(Vec3(camera.position.x+1,camera.position.y,camera.position.z+1))
			end

Link to comment
Share on other sites

So as I understand it when you pick up and object in the world, you want that model to be directly in front of the camera and follow the camera around.

 

I think what I would do is first create a permanent pivot with the camera. Init it at the position/rotation of the camera and then use MoveTo(Vec3(0, 0, 2)) (pos or neg I can't remember) to move the pivot "forward" in front of the camera. Then parent this pivot to the camera so when the camera moves this pivot will always move with it and will always be in front of the camera. Then when you pick up an object all you have to do is assign it's position to this pivots global position. Now it'll always be in front of the camera no matter what.

  • Upvote 1
Link to comment
Share on other sites

Glad to help. This is why I love entity programming so much. The solutions are generally really easy. The only downside is that you end up creating a bunch of "objects", like pivots, and have to manage/free them where if you did it with math you wouldn't need to worry about that, but it's just so much easier to avoid the complicated math. :lol:

Link to comment
Share on other sites

mmm i really didn't understand so much what are you trying to do but i think you can easly use tform..

If you set the position as local you will have the face of your entity (Camera) so just use z axis should be ok.

It's similar to bullet..

Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10.

Link to comment
Share on other sites

mmm i really didn't understand so much what are you trying to do but i think you can easly use tform..

If you set the position as local you will have the face of your entity (Camera) so just use z axis should be ok.

It's similar to bullet..

I tried that but if I would specify a Z value then the object is being placed in the scene's z axis direction, instead of the z axis from the camera point of view. No matter from what angle I approach the object.

Link to comment
Share on other sites

Thanks Joh that looks good.

I have trouble understanding this command:

TFormVector( Vec3(0,0,2),source, destiny )

Correct me if I am wrong: the 'source value' is the global position vector from the picked up entity (oildrum)? This vector is then converted to a local 'destiny' vector (the camera position)? Then the first value (the Vec3) is then added to the destiny command?

Link to comment
Share on other sites

Correct me if I am wrong: the 'source value' is the global position vector from the picked up entity (oildrum)? This vector is then converted to a local 'destiny' vector (the camera position)? Then the first value (the Vec3) is then added to the destiny command?

 

Sorry i was at home..

 

Well no you need to transform the local space of your entity to global space so it will be:

Vec3(0,0,1) (just in front of your entity in local space)

Source entity? camera (you need to place an object in fornt of it right?)

Destination entity? null (null = global, you can also find the position based on other entities, but this isn't your case)

so:

V:TVec3 = TFormVector( Vec3(0,0,1), cam, null );

 

EDITED: (Thanks macklebee to remeber this..)

V= Vec3(EntityPosition(cam).x +V.x,EntityPosition(cam).y +V.y,EntityPosition(cam).z +V.z);

 

Where V is the position of 1 in front of your cam in global space, so you will place the oildrum there.

 

This should work nicely.

 

There is a really nice example here (this make the inverse thing, from global to local):

http://www.leadwerks.com/wiki/index.php?title=TFormVector

Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10.

Link to comment
Share on other sites

Wwesome Joh and Macklebee! :)

I would have never found that out myself. The object is being placed in front of the camera no matter what angle I approach the object now. The only thing remaining is stabalizing the object so that it doesn't start to rotate on incoming collisions.

 

@Rick. I removed it because it wasn't working, but see the txt for what I have so far (editor game script). It is not finished ofcourse, since you can pickup every single model that exists. But At least I have something now where I can base my code on.

 

thanks again for your enormous help! :angry:

 

FPSpickupObjects.zip

Link to comment
Share on other sites

Cool. Mind was relative to another entity so I was able to get it working without the addition. This is generally why I just use the "entity" way though. It's easier for me to think in those terms. When messing around with 3D coords and different spaces my mind sort of gets lost. :)

Link to comment
Share on other sites

The only thing remaining is stabalizing the object so that it doesn't start to rotate on incoming collisions.

I think there are 2 ways to do this:

1) Store object rotation and re-set it every loop (till you keep it)

2) Use SetBodyOmega with a vec3(0) till keep it (this should "freeze" the body)

 

Never tested so it can be wrong.

Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10.

Link to comment
Share on other sites

I think there are 2 ways to do this:

1) Store object rotation and re-set it every loop (till you keep it)

2) Use SetBodyOmega with a vec3(0) till keep it (this should "freeze" the body)

 

Never tested so it can be wrong.

A combination of turning off the bodygravitymode and SetOmega seems to work just fine. :)

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...