Jump to content

macklebee

Members
  • Posts

    3,946
  • Joined

  • Last visited

Everything posted by macklebee

  1. Rereading the posts above, I may have originally misunderstood the turret/mouse interaction. If you want the turret to rotate from a constant camera pick based on mouse pointer position and then just place the sphere when a successful pick is performed when left clicking the mouse, then replace the above 'Script:UpdateWorld()' function with the following code: function Script:UpdateWorld() local window = Window:GetCurrent() local mousepos = window:GetMousePosition() self.pick = self.cam:Pick(mousepos.x,mousepos.y,self.pickinfo,0,true,0) if self.pick then if window:MouseHit(1)==true then self.sphere:SetPosition(self.pickinfo.position,true) self.sphere:Show() end local perfectangle = PerfectAngle(self.entity:GetPosition(true),self.pickinfo.position) local currentangle = self.turret:GetRotation(true).y self.angle=Math:IncAngle(perfectangle,currentangle,5/Time:GetSpeed()) self.turret:SetRotation(0,self.angle,0,true) end end
  2. Playing around with this, there were a couple of modifications I made to the model itself. I scaled the model in a modeling app to 1.5 meters tall so it wasn't so large and I rotated the model so it's initial rotation is facing the +Z direction. Then inside the LE model editor, I extracted an 'idle' and 'walk' animations from the existing animation. Here is the modified model: testturret.zip If I understood correctly what you were trying to accomplish, I made the turret rotate to face a picked point while the actual character movement and rotation of the "legs" were controlled and animated by the 'WASD' keys. Here is the example script to attach to the above model: function Script:Start() local window = Window:GetCurrent() window:ShowMouse() self.legs = self.entity:FindChild("Armature") self.turret = self.entity:FindChild("Hip") self.entitypos = self.entity:GetPosition(true) self.cam = Camera:Create(self.entity) self.cam:SetPosition(self.entitypos.x, self.entitypos.y +3, self.entitypos.z-4, true) self.cam:SetRotation(5,0,0) self.move = 0 self.rotate = 0 self.sphere = Model:Sphere(16) self.sphere:SetColor(1,0,0,1) self.sphere:SetScale(.1,.1,.1) self.sphere:SetPickMode(0) self.sphere:Hide() self.pick = nil self.pickinfo = PickInfo() end function PerfectAngle(pos1,pos2) local dx, dz dx = pos1.x - pos2.x dz = pos1.z - pos2.z return Math:ATan2(dx,dz) end function Script:UpdateWorld() local window = Window:GetCurrent() if window:MouseHit(1)==true then local mousepos = window:GetMousePosition() self.pick = self.cam:Pick(mousepos.x,mousepos.y,self.pickinfo,0,true,0) end if self.pick then self.sphere:SetPosition(self.pickinfo.position,true) self.sphere:Show() local perfectangle = PerfectAngle(self.entity:GetPosition(true),self.pickinfo.position) local currentangle = self.turret:GetRotation(true).y self.angle=Math:IncAngle(perfectangle,currentangle,5/Time:GetSpeed()) self.turret:SetRotation(0,self.angle,0,true) end end function Script:Draw() if math.abs(self.move)>0.1 then local t = Time:GetCurrent() self.legs:SetAnimationFrame(t/10,1.0,"walk",true) else self.legs:SetAnimationFrame(0,1.0,"idle",true) end end function Script:UpdatePhysics() local window = Window:GetCurrent() self.move = Math:Curve(((window:KeyDown(Key.W) and 1 or 0) - (window:KeyDown(Key.S) and 1 or 0)),self.move,10) self.rotate = self.rotate + ((window:KeyDown(Key.D) and 1 or 0) - (window:KeyDown(Key.A) and 1 or 0)) self.entity:SetInput(self.rotate,self.move*3,0,0,false,10) end
  3. Added. http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/object/objectgetclass-r19
  4. It is hidden in the forums here: http://www.leadwerks.com/werkspace/topic/10139-leadwerks-map-class/#entry75115 Hopefully this will be one of the things that Josh and Aggror add to the revamped documentation/tutorials.
  5. If you are using c++, I believe you can still use opengl commands. Or you can do it via a shader. Unzip and place this shader in your project's 'Shaders/Drawing' folder: drawimageparts.zip To Use: shader = Shader:Load("Shaders/Drawing/drawimageparts.shader") shader:SetVec2("uvcoords", Vec2(#,#)) shader:SetVec2("zoom", Vec2(#,#)) oldshader = context:GetShader() context:SetShader(shader) context:DrawImage(LoadedImageToDraw, x , y, w, h) context:SetShader(oldshader) Example code showing usage: function App:Start() self.window = Window:Create("Part of Image Example",0,0,800,600) self.context = Context:Create(self.window) self.world = World:Create() self.camera = Camera:Create() self.texture = Texture:Load("Materials/Developer/bluegrid.tex") self.shader = Shader:Load("Shaders/Drawing/drawimageparts.shader")--load shader uvcoords = 1.0 zoom = 2.0 return true end function App:Loop() if (self.window:Closed() or self.window:KeyDown(Key.Escape)) then return false end uvcoords = uvcoords + ((self.window:KeyHit(Key.Up) and 1 or 0) - (self.window:KeyHit(Key.Down) and 1 or 0)) * 0.1 zoom = zoom + ((self.window:KeyHit(Key.Right) and 1 or 0) - (self.window:KeyHit(Key.Left) and 1 or 0)) * 0.1 self.shader:SetVec2("uvcoords", Vec2(uvcoords))--set uvcoords in shader self.shader:SetVec2("zoom", Vec2(zoom))--set zoom in shader Time:Update() self.world:Update() self.world:Render() self.oldshader = self.context:GetShader()--get current shader self.context:SetBlendMode(Blend.Alpha) self.context:SetShader(self.shader)--set new shader self.context:DrawImage(self.texture,405,150,300,300)--clipped/scaled image self.context:SetShader(self.oldshader)--set back to previous shader self.context:DrawImage(self.texture,100,150,300,300)--normal drawimage self.context:DrawText("Press Up/Down to change uvcoords", 0, 2) self.context:DrawText("UVCoords: "..uvcoords..", "..uvcoords, 0, 22) self.context:DrawText("Press Right/Left to change zoom", 0, 42) self.context:DrawText("Zoom: "..zoom..", "..zoom, 0, 62) self.context:SetBlendMode(Blend.Solid) self.context:Sync(); return true end
  6. Use the texture editor to set the *.tex to uncompressed. The default for *.tex is DXT1 which will scale the image to a power of 2. All of the DXT# formats will do this. Also make sure mipmaps is unchecked then save the file.
  7. As it may be related to the problem above, SetPosition has to be used after the source is initially played or the source is not actually positioned. Just flipping the order of 'self.source:Play()' and 'self.source:SetPosition(Vec3(0,0,3))' in the above script will cause the sound to be heard at full volume no matter what the range is set to.
  8. Also noticed that creating a listener makes no difference in the behavior of this script. Is a listener being created automatically when the context is created? Edit -- doesnt appear to be the case. Commenting out the context still allows sounds to be played. hmmm...
  9. At first thought this was an issue with mono vs stereo sounds, but tracked down the issue to Source:SetRange(). Whenever the range of a mono sound is set to 1.0 or below, it will play at full volume no matter how far away the source is from the listener. Using a slightly modified version of the Source:SetRange lua example, the sound will play when the range is greater than 2 (which is the distance from source to listener) and when the range is equal or less than 1.0: function App:Start() self.window = Window:Create("Source SetRange Issue",0,0,400,300) self.context = Context:Create(self.window) local sound = Sound:Load("Sound/doors/fdn_door_automatic_servo_driven_close_short_05.wav") self.source = Source:Create() self.source:SetSound(sound) sound:Release() self.source:SetLoopMode(true) self.source:Play() self.source:SetPosition(Vec3(0,0,2)) local listener = Listener:Create() listener:SetPosition(0,0,0) range = 0.1 toggle = 0.005 return true end function App:Loop() if self.window:Closed() or self.window:KeyHit(Key.Escape) then return false end range = range + toggle if range>=3 then toggle = -0.005 end if range<=0 then toggle = 0.005 end self.source:SetRange(range) Time:Update() self.context:SetColor(0,0,0) self.context:Clear() self.context:SetColor(1,1,1) self.context:SetBlendMode(Blend.Alpha) self.context:DrawText(string.format("Range: %.2f",range),0,2) self.context:Sync(true) return true end
  10. no need for any apology, he had given me more info via chat than what was posted here... so no worries.
  11. I believe he is using csg created boxes so he will also need to attach an empty script to each so they are not collapsed into the scene. And since he is using the sliding door script that is using a physics joint for movement, he just needs to set his pivot mass to be greater than 0.
  12. There is an inherent basic script for loading a sound located under Scripts/Objects/Sound named noise.lua. Attach that script to a pivot and then pick the sound file you wish to play.
  13. I assume that the documentation is in the process of being reworked.
  14. http://www.leadwerks.com/werkspace/topic/11423-deleted-the-object-search-window-on-the-right/#entry82646 the same theory applies to the script editor as the world editor... if you do not find it on the right side inner wall of the script editor, try click/hold and drag from the left side inner wall...
  15. Can we make this a user selected option for those of us that want to keep vertex colors?
  16. Thats really good info to know. So basically means anything other than animated characters can be scaled to fit in LE, at least for my needs with parenting.
  17. Thats my point. Dont scale the mdl model in LE. Scale the fbx model to the size you want in a modelling app prior to importing into LE.
  18. I see the link but I dont have access to LE for another couple weeks - but the comment about not being posted in the original post, is that it is never mentioned if a pick radius of 0 and polygon pick mode had been tried. Spherical picks are slower and less precise just by their nature. Also using the pick's collisiontype to act as a filter will give better control than just picking everything that is pickable.
  19. The best way is to set the proper size of the model in a modeling app prior to importing into leadwerks. That way the models scale in LE is 1,1,1 and you dont have to worry about bizzare results in local position when parenting due to scaling.
  20. As I dont have a way to test and its not posted in the original post, but have you tried setting the entities' pick modes to polygon pick and the pick's radius to 0? My understanding is that is the most precise pick on objects that are not animated models. Spherical picks are supposedly slower and with a true setting for closest return I could see how it might occasionally give unexpected results. Also, are you using a specific collisiontype for your pick? If the pick's collisiontype is set to 0 which will collide with everything pickable and you are using a pick radius then that could cause problems as well. Also, I never had an opportunity to test and its not in the documentation that I am aware of, but is the radius value in meters? If so, then it would definitely cause issues getting a precise pick. Also TJ, I would also suggest setting that sphere's pick mode to none so it is ignored when troubleshooting.
  21. The only thing I see being installed with the 24 height map workshop item is the 'thumn.tex' located in the project root directory. It appears that the actual heightmaps are not being installed.
  22. We need more information than what you are providing or all anyone can do is guess. What were the exact changes that you made in the properties tab? Any changes to the script itself? Any other changes on the physics tab? We need this kind of information to replicate the problem in order to help you.
  23. Setting collisiontype to '0' on entities means no collision whereas setting the collisiontype on a raycast to '0' means it will report a collision with everything.
  24. http://www.leadwerks.com/werkspace/page/tutorials/_/script/introduction-to-lua-scripting-r103
  25. You could perform a count of world entities and then cycle through confirming name, but i would assume that would be too expensive and might cause a noticeable pause in the game when adding or removing. One way might be to add a script to the crate model that checks for a global table (or creates the table if it doesn't exist) that adds the crates entities to it. Then all you would have to do is count the number of items in the table. When the crate is removed from the scene then the script can use the function Script:Detach() to decrement the table.
×
×
  • Create New...