Andy Gilbert Posted July 5, 2013 Share Posted July 5, 2013 When you use this function in a script attached to some CSG or a model it works fine: if (self.window:KeyHit(Key.Right)) then mypos = self.entity:GetPosition() self.entity:SetPosition(mypos.x+2,mypos.y,mypos.z) end If you attach the above to the camera, it causes strange issues. The main one being the camera doesnt move with keyHits. Andy The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do. Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d Link to comment Share on other sites More sharing options...
beo6 Posted July 6, 2013 Share Posted July 6, 2013 You should use KeyDown for movement since KeyHit is only called once when you pressed the key and KeyDown as long as you hold the key down. Link to comment Share on other sites More sharing options...
Andy Gilbert Posted July 6, 2013 Author Share Posted July 6, 2013 It's not for movement it's just an example to show how its not working. I want to make it so when the user hits a key it moves something once. Using move down will move it many times with one press. I only want it to happen once. Andy The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do. Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d Link to comment Share on other sites More sharing options...
Rick Posted July 6, 2013 Share Posted July 6, 2013 Does that even run without error for you when placed in an entity script and attached to anything? self.window doesn't exist in entity scripts. If I change self.window to App.window then it runs for me but I notice it doesn't move the camera. Will see what's up. [EDIT] I assume this is a Lua game. Go into Scripts/App.lua and comment out the line that has self.camera=Camera:Create() and it should work then. The problem is the default Lua app creates a camera in code (App.lua) so if you drag in a camera your scene now has 2 cameras and it seems to by default take the one created in App.lua. Your other option would be NOT to drag in a camera entity into your scene and in code access the global camera created in App.lua via App.camera. Link to comment Share on other sites More sharing options...
Andy Gilbert Posted July 8, 2013 Author Share Posted July 8, 2013 Hi Rick. My App.lua doesnt have the self.camera=Camera:Create() ? I can confirm there is noly one camera in the scene, yet the problem still persists. Andy The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do. Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d Link to comment Share on other sites More sharing options...
Andy Gilbert Posted July 8, 2013 Author Share Posted July 8, 2013 But i did find another object using the same script which was screwing things up, working great now. Thanskd The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do. Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d Link to comment Share on other sites More sharing options...
beo6 Posted July 8, 2013 Share Posted July 8, 2013 Maybe an issue with global variables? You should use local mypos = self.entity:GetPosition() Link to comment Share on other sites More sharing options...
Rick Posted July 8, 2013 Share Posted July 8, 2013 If another script had a KeyHit() on the same key that could do it since KeyHit() will only register once in a cycle. Maybe it was registering that key in the other script and never making it into the if check in this script? @Andy this is one of the reasons to sometimes do what beo6 mention with using KeyDown(). You can make a modified KeyHit() where you use KeyDown() and a boolean check in the script so it only fires once per frame, but if 2 scripts use this method they will at least both get into the if check of their scripts. Link to comment Share on other sites More sharing options...
Admin Posted July 14, 2013 Share Posted July 14, 2013 Please provide an example I can run and produce the error with. Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts