• Quick question: Fix model position according to the angles of its parent
    7 replies, posted
I am having this little issue, when I attach the model to shelf via "SetParent()" and to be specific, via this method: [lua] Shelf.Attachment:SetPos(self:GetPos() + Shelf.Pos) Shelf.Attachment:SetAngles(self:GetAngles() + Angle(0,0,90)) Shelf.Attachment:SetParent(self) [/lua] Shelf.Pos = Vector(-20,7,4) ;the model gets attached differently according to the angles it's parent had during parenting. This is what I meant: [img]http://cloud-2.steampowered.com/ugc/612767741203909568/EE8DA3A8AF92C15D6A4EDC4AD92622428F7971B5/1024x768.resizedimage[/img]
Try to play around with ang:RotateAroundAxis(dir, vector) instead of simply adding angle to another angle.
[QUOTE=Robotboy655;40838675]Try to play around with ang:RotateAroundAxis(dir, vector) instead of simply adding angle to another angle.[/QUOTE] Actually Angle is fine, the only problem is that I add a Vector to Vector not according to the angle. So if the shelf is rotated by 90', I still add the same amount of X and Y which makes it placed out of the shelf
Oh, I get it. Then you need to use shelf:Forward() * x shelf:Right() * y and shelf:Up() * z to position the gun, instead of adding the vector. So you do [code]Shelf.Attachment:SetPos(self:GetPos() + self:GetForward() * Shelf.Pos.x + self:GetRight() * Shelf.Pos.y + self:GetUp() * Shelf.Pos.z )[/code] This code might not work as you expect it to, so you will need to adjust the values of your Shelf.Pos
You are better off using LocalToWorld tbh, easier, less function calls and faster.
[QUOTE=Robotboy655;40838787]Oh, I get it. Then you need to use shelf:Forward() * x shelf:Right() * y and shelf:Up() * z to position the gun, instead of adding the vector. So you do [code]Shelf.Attachment:SetPos(self:GetPos() + self:GetForward() * Shelf.Pos.x + self:GetRight() * Shelf.Pos.y + self:GetUp() * Shelf.Pos.z )[/code] This code might not work as you expect it to, so you will need to adjust the values of your Shelf.Pos[/QUOTE] I'll try it later @Edit: LocalToWorld ? I got a little rusty I guess, I'll try it aswell
Pseudo-ish: [lua] local pos, ang = LocalToWorld(relativePosition, relativeOrientation, shelf:GetPos(), shelf:GetAngles()) shelf.attachment:SetPos(pos) shelf.attachment:SetAngles(ang) [/lua]
[QUOTE=Wizard of Ass;40838876]Pseudo-ish: [lua] local pos, ang = LocalToWorld(relativePosition, relativeOrientation, shelf:GetPos(), shelf:GetAngles()) shelf.attachment:SetPos(pos) shelf.attachment:SetAngles(ang) [/lua][/QUOTE] Okay, I am gonna try it now. I got it to work. Thanks!
Sorry, you need to Log In to post a reply to this thread.