How to make a open and close entity out of 2 props (like a pirate chest)
7 replies, posted
I have looked all over and asked friends but no answer on how to do this.
I have made 2 models for a pirates chest. one the body that is empty inside and the second the lid. I want to know how to make it an open and close entity with the use key kind of like an ammo crate but without making any animations in something like 3ds max.
So if anyone can help me how do I do it ?
So you want to animate it without making an animation for it?
I have never tried anything like this before, but you can probably write some kind of lua script that uses the [B][URL="http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index8d72.html?title=Entity.SetAngles"]SetAngles[/URL][/B] function.
From a purely conceptual approach, I think you would need to spawn the chest body somewhere in the world. And then spawn the chest lid above the body (obviously. Approx the same position + height offset) and parent the lid to the chest item itself. After that, you could have some kind of a script like this which is activated "OnUse"
[b]Note: Completely untested. This is really just rough psuedo-code.[/b]
[lua]
timer.Simple(0.05, function(Entity)
if ( Entity:GetAngles()[1] < 90 ) then
Entity:SetAngles( Entity:GetAngles() + Vector( 1, 0, 0) );
end
end, lidEntityReferenceHere);
[/lua]
I don't know for sure, but I would bet the performance of a solution like this is far worse than just making the animation. But I doubt it would be anything noticeable.
thanks for the reply I had though nobody would of really attempted this before. I did not want it to be a ragdoll and I wanted it to be an entity but I did not like the idea of animating it as I personally am not very good at doing it.
I will play around with what you suggested in a day or two when I have time. I will post a video if it works and the final code.
Make an animation for a model. Don't use 2 props, it won't look smooth.
OK in that case can anyone make me an example code of how to make it work. I assume it is rather simple just a small code telling it to use animation for so many seconds on the press of usekey.
SetAnimation i think? sopmething like that.
[b][url=http://bananatree.im/wiki/wiki.garrysmod.com/indexfa6f.html?title=Entity.SetAnimation]Entity.SetAnimation [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] unfortunately will not [I]visually[/I] animate the model, as stated on the wiki. (Which is odd, considering that one would assume it does that because of it's name, but oh well).
It appears you'd actually have to use [b][url=http://bananatree.im/wiki/wiki.garrysmod.com/index3624.html?title=Entity.SetSequence]Entity.SetSequence [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] with the function arguments being [b][url=http://bananatree.im/wiki/wiki.garrysmod.com/index94b2.html?title=Entity.LookupSequence]Entity.LookupSequence [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]. You may also want to check out [b][url=http://bananatree.im/wiki/wiki.garrysmod.com/indexfd35.html?title=Entity.ResetSequence]Entity.ResetSequence [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b].
[editline]hi[/editline]
Also, I forgot to mention; make sure you use:
[lua] Entity:SetUseType(SIMPLE_USE)[/lua]
otherwise, every tick the animation would reset due to the constant 'use'-ing of the entity.
Thanks for all the help with luck this should work just about work out if I put my mind to it.
If this works I will be able to hopefully make a range of working items. Wardrobes doors and other crap like that just for fun.
Sorry, you need to Log In to post a reply to this thread.