Jump to content

Script: Move Character to mouse position?


richardl008
 Share

Recommended Posts

I would assume its just a script using entity:GoToPoint() and camera:Pick()?

 

example:

window = Window:Create("example",0,0,800,600)

context = Context:Create(window)

world = World:Create()

local camera = Camera:Create()

camera:SetRotation(45,0,0)

camera:Move(0,0,-8)

local light = DirectionalLight:Create()

light:SetRotation(35,35,0)

camera:SetDebugNavigationMode(true)

 

local ground = Model:Box(10,1,10)

ground:SetPosition(0,-0.5,0)

ground:SetColor(0.0,0.25,0.0)

local shape = Shape:Box(0,0,0, 0,0,0, 10,1,10)

ground:SetShape(shape)

shape:Release()

 

entity = Model:Box(1,1,3)

entity:SetColor(0.0,0.0,1.0)

entity:SetPosition(0,0.5,0)

local shape = Shape:Box(0,0,0,0,0,0,1,1,3)

entity:SetShape(shape)

shape:Release()

 

ground:SetNavigationMode(true)

entity:SetNavigationMode(true)

world:BuildNavMesh()

 

player = Pivot:Create()

local visiblecapsule = Model:Cylinder(16,player)

visiblecapsule:SetScale(1,2,1)

visiblecapsule:SetPosition(0,1,0)

player:SetPosition(-4,0,0)

player:SetMass(1)

player:SetPhysicsMode(Entity.CharacterPhysics)

 

while window:KeyHit(Key.Escape)==false do

if window:Closed() then break end

 

if window:MouseHit(1) then

local pickinfo = PickInfo()

local p = window:GetMousePosition()

if camera:Pick(p.x,p.y,pickinfo,0,true) then

System:Print(pickinfo.position:ToString())

player:GoToPoint(pickinfo.position,1.4,1)

end

end

 

Time:Update()

world:Update()

world:Render()

context:Sync(true)

end

  • Upvote 1

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