awgsknite Posted February 21, 2015 Share Posted February 21, 2015 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 Quote http://steamcommunity.com/profiles/76561197977392956/7977392956/ Link to comment Share on other sites More sharing options...
shadmar Posted February 21, 2015 Share Posted February 21, 2015 Parent the camera, the player can be several things. Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
awgsknite Posted February 21, 2015 Author Share Posted February 21, 2015 but it is an FPS game. So isn't the camera already parent to the player and isn't the player the camera ? Quote http://steamcommunity.com/profiles/76561197977392956/7977392956/ Link to comment Share on other sites More sharing options...
shadmar Posted February 21, 2015 Share Posted February 21, 2015 It's not so simple, to witch of these are you a parenting when you just do SetParent(player) ? Player is a model Player is a charactercontroller Player is a camera Player is a pivot Player is a flashlight Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
awgsknite Posted February 21, 2015 Author Share Posted February 21, 2015 I'm using the FPSPlayer that has the player variable in it. so player is a charactercontroller Quote http://steamcommunity.com/profiles/76561197977392956/7977392956/ Link to comment Share on other sites More sharing options...
Aaron Symons Posted February 21, 2015 Share Posted February 21, 2015 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) Quote Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660 Link to comment Share on other sites More sharing options...
awgsknite Posted February 22, 2015 Author Share Posted February 22, 2015 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 ? Quote http://steamcommunity.com/profiles/76561197977392956/7977392956/ Link to comment Share on other sites More sharing options...
awgsknite Posted February 22, 2015 Author Share Posted February 22, 2015 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 ? Quote http://steamcommunity.com/profiles/76561197977392956/7977392956/ Link to comment Share on other sites More sharing options...
awgsknite Posted February 22, 2015 Author Share Posted February 22, 2015 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 Quote http://steamcommunity.com/profiles/76561197977392956/7977392956/ Link to comment Share on other sites More sharing options...
shadmar Posted February 22, 2015 Share Posted February 22, 2015 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 Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
awgsknite Posted February 25, 2015 Author Share Posted February 25, 2015 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. Quote http://steamcommunity.com/profiles/76561197977392956/7977392956/ Link to comment Share on other sites More sharing options...
Recommended Posts
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.