So I am trying to make a SWEP were you can place a C4 on a prop or door and it will blow it up but the model I am using have the center point in the center of the model so when I use the following code:
[CODE]
local tr = ply:GetEyeTrace()
bomb = ents.Create("bomb_ent")
bomb:SetPos(tr.HitPos)
bomb:SetAngles( tr.Entity:GetAngles() )
bomb:Spawn()
bomb:SetParent(tr.Entity)
[/CODE]
It will place half the model inside the prop and the other half outside it.
On the left is how I want it to be but on the right is how it spawns. How can I make it "retract" by a couple of units?
[T]https://i.gyazo.com/9663d628d3bcfe8fe8fc44f201743023.png[/T]
I'm not sure but try changing the code around like this:
[code]
local tr = ply:GetEyeTrace()
bomb = ents.Create("bomb_ent")
bomb:SetPos(tr.HitPos)
bomb:SetAngles( tr.Entity:GetAngles() )
bomb:SetParent(tr.Entity)
bomb:Spawn()
[/code]
This could be completely wrong but I don't have a lot of experience with entity coding.
I swapped the parent and spawn code around so that the parent is set prior to the spawn. I'll see if I can figure it out, I'll keep checking this thread :)
It's not that I don't think as when I removed the parent part and made it just freeze it was still the same.
[QUOTE=OutlawReaper;51562693]It's not that I don't think as when I removed the parent part and made it just freeze it was still the same.[/QUOTE]
Hmm, I'm not really sure but you could try: [code] SetPos(tr.HitPos + 5) -- Add 5 to the entity's position[/code]
This could be completely wrong but it's worth a shot right? I'll see if I can find any information about this.
[lua]
local tr = pl:GetEyeTraceNoCursor()
local prop = ents.Create("prop")
prop:SetModel(arg[1])
prop:SetPos( tr.HitPos + (tr.Normal*-1) * (prop:OBBCenter().x-prop:OBBMins().x) )
prop:SetAngles( tr.HitNormal:Angle() )
prop:Spawn()
[/lua]
tr.HitNormal returns the [I]vector direction[/I] of the surface you hit, use "Angle()" to convert to an angle. (tr.HitNormal:Angle())
tr.Normal returns the direction from trace start to trace end. Reverse that to get the "retract" direction you desire your entity to move. (tr.Normal*-1)
You only want to "retract" the entity half of its overall width, considering it spawns in the center. Take the entity center point, and the bottom corner point. Extract the x length between the two. (prop:OBBCenter().x-prop:OBBMins().x)
[quote](Trace Results) [URL]https://wiki.garrysmod.com/page/Structures/TraceResult[/URL]
(OBBCenter) [URL]https://www.maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexa8eb.html[/URL]
(OBBMaxs) [URL]https://www.maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index1775.html[/URL]
(Angle) [URL]https://wiki.garrysmod.com/page/Vector/Angle[/URL][/quote]
Check those out if you wanna do some learnin.
[QUOTE=find me;51562775][lua]
local tr = pl:GetEyeTraceNoCursor()
local prop = ents.Create("prop")
prop:SetModel(arg[1])
prop:SetPos( tr.HitPos + (tr.Normal*-1) * (prop:OBBCenter().x-prop:OBBMins().x) )
prop:SetAngles(tr.HitNormal:Angle())
prop:Spawn()
[/lua]
tr.HitNormal returns the vector direction of the surface you hit, use "Angle()" to convert to an angle. (tr.HitNormal:Angle())
tr.Normal returns the direction from trace start to trace end. Reverse that to get the "retract" direction you desire your entity to move. (tr.Normal*-1)
You only want to "retract" the entity half of its overall width, considering it spawns in the center. Take the entity center point, and the bottom corner point. Extract the x length between the two then divide by 2. (prop:OBBCenter().x-prop:OBBMins().x)[/QUOTE]
And that's me completely lost :what: :goodjob:
Thanks find me. It works.
Sorry, you need to Log In to post a reply to this thread.