Andy Gilbert Posted August 19, 2011 Share Posted August 19, 2011 Hi, im trying to work out how i can do 3D RTS similer style movement using LE and lua? So far it appears impossible as i cant find a way to get the mosue coords in 3D? Does anyone know how this could be done? Cheers Andy Quote 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 August 19, 2011 Share Posted August 19, 2011 I'm confused as to what you are asking? Maybe look at CameraPick? Quote Link to comment Share on other sites More sharing options...
Andy Gilbert Posted August 19, 2011 Author Share Posted August 19, 2011 Hi Rick, im probably confused myself, but i would have thought, in order to get a 3d object to move towards the mouse in 3d space? I need to know the 3d coords or the mouse? How can i get them using lua? Thanks Andy Quote 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 August 19, 2011 Share Posted August 19, 2011 I think CameraPick should give you what you want. You use it to select your unit, then you use it to get a point (x,y,z) selected on terrain or model and that is where you move your unit to. Quote Link to comment Share on other sites More sharing options...
macklebee Posted August 19, 2011 Share Posted August 19, 2011 http://www.leadwerks.com/werkspace/topic/1762-pointnclick/ Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Andy Gilbert Posted August 19, 2011 Author Share Posted August 19, 2011 Spot on! I'll give it a go. Thanks both Andy Quote 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 August 19, 2011 Author Share Posted August 19, 2011 Not sure what im doing wrong here? This code below doesnt work but ALSO doesnt error: local pick=CameraPick(fw.main.camera,Vec3(MouseX(),MouseY(),30.0),0,0) if pick then object.cameraPivot:SetPosition(Vec3(pick.x,0,pick.z)) self.model:Point(object.cameraPivot,1,1) end if i change the CameraPick Z value (above is 30) to anything below 30 it errors (Index for object is not valid field or method) anything below doesnt error but also doesnt work? Anyknow know why? This is used within the script of the object im trying to use. Thanks Andy Quote 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...
macklebee Posted August 19, 2011 Share Posted August 19, 2011 without actually being able to see what is happening in the code, try: local pick=CameraPick(fw.main.camera,Vec3(MouseX(),MouseY(),30.0),0,0) if pick~=nil then self.cameraPivot:SetPosition(Vec3(pick.position.x,0,pick.position.z)) self.model:Point(self.cameraPivot,1,1) end Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
macklebee Posted August 19, 2011 Share Posted August 19, 2011 here is Gimpy's original version converted to lua: --original bmx code by GIMPY require("Scripts/constants/engine_const") RegisterAbstractPath("") Graphics(800,600) fw=CreateFramework() fw.main.camera:SetPosition(Vec3(0, 45, - 45)) light = CreateDirectionalLight() light:SetRotation(Vec3(65, 45, 0)) piv = CreatePivot() cube = CreateCube() plane = CreatePlane() plane:SetScale(Vec3(100,0.1,100)) plane:Paint(LoadMaterial("abstract::cobblestones.mat")) while KeyHit(KEY_ESCAPE)==0 do fw.main.camera:SetPosition(Vec3(cube.position.x,cube.position.y+25,cube.position.z-25)) fw.main.camera:Point(cube,3,1) if MouseDown(1)==1 then local pick = CameraPick(fw.main.camera, Vec3(MouseX(), MouseY(), 1000)) if pick~=nil then piv:SetPosition(Vec3(pick.position.x,.5,pick.position.z)) cube:Point(piv,3,1) speed = 0.3 end end if EntityDistance(cube,piv)<1.2 then speed = 0 end cube:Move(Vec3(0,0,speed)) fw:Update() fw:Render() Flip(1) end Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Andy Gilbert Posted August 19, 2011 Author Share Posted August 19, 2011 Cheers Macklebee, spot on seems to be working fine now. Thanks Andy Quote 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 August 19, 2011 Author Share Posted August 19, 2011 Although, i still cant work out why this flips my object around? It does a 180 roll for some reason but then works perfectly just upside down, exit game mode and it turns back around again? this appears to be happeneing from the "point" command?? Any ideas? Andy Quote 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...
macklebee Posted August 19, 2011 Share Posted August 19, 2011 probably because you are rotating the model around the x-axis self.model:Point(self.cameraPivot,1,1) try using the z-axis: self.model:Point(self.cameraPivot,3,1) i did not know with your code above if that was intentional or not... Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.