Jump to content

parent to center


awgsknite
 Share

Recommended Posts

Okay i bean trying to do this all day and i have to ask now since it has taken too much time already.

 

How do i put an object infront of my fps player while it is parent ?

 

Here is what works so far:

set inside FPSPlayer.lua..

local modelview = Prefab:Load("Prefabs/modelofmodels.pfb")

 

modelview:SetPosition(0,2,2)

 

modelview:SetParent(player)

 

yeah so those 3 lines puts the prefab model near the player if the player is near the position of 0,0,0 the x,y,z....it really should not be used to center anything in the middle of the screen 'cos it don't. It just parents the model to the player if you set the object to trigger and prop with no collision as i found out. If you set it to have collision and/or mass then you got it falling or dissappearing. Also if the player moves around and then the parent is set the model sometimes appears in some other odd place like right behind you !

 

Anyways, i bean trying diff. codes and they all dont work for me to get it to the center of screen and parented at the same time. I tried GetMousePosition() code and it did not recognize it amongst other bizarre code. LoL.

I even troid to use the camera code: modelview:SetPosition(camera:GetPosition()) but then it didn't know what camera is ! Then i tried to get player.camera and it didnt know that ! etc.. etc. etc..

Can anyone help this LE noob out ? Thanks in advance

Link to comment
Share on other sites

If you're doing it via script, try setting the global coordinates to true, as described here:

 

 entity:SetPosition(x, y, z, true)

 

Get the player's position, then add onto that, eg: if you want the object 2 units in front of the player on the X axis:

 


-- Get player position (if this script is attached to the player)

local playerPos = self.entity:GetPosition()

 

-- Set the object's position, using global coordinates

self.object:SetPosition(playerPos.x + 2, playerPos.y, playerPos.z, true)

Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660

Link to comment
Share on other sites

Thanks but that didnt work it just does the same thing.

I couldnt make that code the exact same as what you have there cos it kept saying error at setposition. Heres the code :

 

local playerPos = self.entity:GetPosition()

-- Set the object's position, using global coordinates

modelview:SetPosition(playerPos.x, playerPos.y, playerPos.z, true)

modelview:SetScale(100,100,100)

modelview:SetParent(player)

 

I guess what im looking for is getting the center of the screen instead which would be a completely different code

 

Unless it's because this script is attached to the child of the player that is a pivot.Then what do i do ?

Link to comment
Share on other sites

this problem seems to be the same problem or bug as this :

http://www.leadwerks.com/werkspace/topic/11950-aligntovector-entity-childs-not-aligned/#entry87421

 

im going to try to put this script on the fps player that is no child and see what happens

but how do i call a function from a diff. script ?

Link to comment
Share on other sites

ok i tried to use the no child idea and from my fpsplayer I added a pivot as a child(drag and drop) that has my gui on it and from it(child) I am calling to another script's function(fpsplayer function) to create a prefab infront of the player. But each time the player moves, the prefab is placed in a different place and never where the setposition was set(directly infront of the fpsplayer)

 

so im stuck and cannot place my prefab directly infront of the camera

Link to comment
Share on other sites

Here is what I use to attach something to camera:

 


--CamAttach.lua

function Script:Start()

self.cam = self.entity:GetParent().script.camera

self.entity:SetParent(self.cam) -- this will oveerride the parenting to the charactercontroller.

end

post-747-0-06529900-1424596980_thumb.jpg

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

I got this fixed finally !

 

I could not do this by programming so now I do it this way. All the codes I tried never worked.

 

I had to manually drag & drop the scene object making it a child of the player. Now it is in the center of the screen where I placed it right in front of my player. I would have wanted to do it by programming but I could not.

 

@shadmar : Thanks ! That there idea you have works but I wanted to have the scene object not actually be a child to begin with on my player. I actually wanted to make the object prefab appear infront of the screen (fps player) and not have it already as a child of the player.

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...