Question

I'm trying to setup a free flying camera in XNA. I'm using Lua connected mostly to the CLR to control the camera in this instance.

I've tried the following so far:

dkeys={}

LocalController.KeyDown:Add(function(s,e)
    dkeys[KeyboardKey.FromInt(e)]=true
    if e==KeyboardKey.W then
        local r,x=coroutine.resume(coroutine.create(function()
            while wait(.5) and dkeys['W'] do
                local LookVector=Vector3:Subtract(LocalCamera.Target,LocalCamera.Position)
                LookVector:Normalize()
                LookVector=Vector3:Multiply(LookVector,Vector3:Create(.1,.1,.1))
                LocalCamera.Position=Vector3:Add(LocalCamera.Position,LookVector)
                LocalCamera.Position=Vector3:Add(LocalCamera.Target,LookVector)
            end
        end))
    end
end)

I'm obviously not doing something right because the result turns into the camera bouncing back and forth between the positive and negative form of the same point.

Here is the code I'm using on KeyUp:

LocalController.KeyUp:Add(function(s,e)
    dkeys[KeyboardKey.FromInt(e)]=false
end)

Have I misinterpreted what a LookVector is? LocalCamera is the current camera object with Target being the position the camera is looking at and Position being the point it's looking at the Target from.

Was it helpful?

Solution

You're assigning LocalCamera.Position twice. Did you mean to assign LocalCamera.Target instead?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top