Jump to content

RTS style movement using lua? Not possible?


Andy Gilbert
 Share

Recommended Posts

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

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

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

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

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

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

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

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

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

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

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

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

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...

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...