Jump to content

keyHit bug when moving camera.


Recommended Posts

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

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

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

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

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

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...