• Rotating prop relative to ent
    7 replies, posted
Hey. As part of a small project I've started on, I wanted to make it so that when I touched my first ent with my second ent attached a prop to it. https://files.facepunch.com/forum/upload/300107/2b8ee64b-6141-4e57-b302-95444a5e09b5/1.gif As you can see I've manged to get that far, and what I wanted to do next was have the prop to be rotated 90 degrees, however when I've tried to do this it doesn't really rotate properly relative to the ent, like when it is at a weird angle. Essentially, instead of it being like this inside the ent: https://files.facepunch.com/forum/upload/300107/a97ea2bf-f5ac-4847-9970-67457930304a/2.png I want it to be like this: https://files.facepunch.com/forum/upload/300107/7668beab-092d-4709-8b77-840f6e64d06f/3.png This is the code I've got so far: function ENT:Touch( ent ) if ent:GetName() == "bomb_gen" then local bomb = ents.Create( "prop_dynamic" )     bomb:SetModel( "models/items/car_battery01.mdl" )     bomb:SetPos( ent:GetPos() + ( ent:GetAngles():Forward() * 5) - ( ent:GetAngles():Up() * 12 ) - (ent:GetAngles():Right() * 4.5))     bomb:SetAngles(ent:GetAngles())     bomb:SetParent( ent )     bomb:SetColor( Color(150,150,150) )     ent:DeleteOnRemove( bomb )     bomb:Spawn()     self:Remove() end end Any help on the matter would be greatly appreciated. Thank you!
You can use Angle/RotateAroundAxis to rotate an angle around a specific axis. Using this you can feed the directional vector of the entity you want to rotate relative, so for example to do what you want you can do something like --Store a copy of the entities angles local angle = theEntYouWantToRotate:GetAngles() --Now rotate the angle around the right axis of the other entity angle:RotateAroundAxis(theOtherEnt:GetAngles():Right(), 90) --Set the angle back theEntYouWantToRotate:SetAngles(angle) Is that what you want?
Thank you so much! That worked. https://files.facepunch.com/forum/upload/300107/3b59435c-14de-4563-98b5-6fdd84091796/4.png
A further issue that's just come up now is that cam3d2d doesn't seem to show when it is in front of the the ent that is created. If anyone knows how to fix this that would be rather helpful, as I've been having a hard time trying to figure it out. Thank you! https://files.facepunch.com/forum/upload/300107/c84e351c-df00-40ed-b1da-5330bd5d8088/6.gif
make the 2d3d after you attach it and see if that fixes it. (Im not sure if this works or not)
If you are drawing the 3D2D in the ENT:Draw(), dont do that and draw it in a PostDrawTranslucentRenderables hook, that should fix it
Thank you Gmod4phun, that worked.
Update. Tried to add a spinning wheel on the side of the ent using RotateAroundAxis(), however the prop does not stay aligned when the parent ent moves. Does anybody know how to fix this? https://files.facepunch.com/forum/upload/300107/dcf81712-c8c0-4ce8-ad01-d1fc521f1789/7.gif
Sorry, you need to Log In to post a reply to this thread.