Jump to content

Trying to build up a basic VR functions


Kerag
 Share

Recommended Posts

Hi! I liked your engine. But VR player script misses all the standard features that required to build a descent VR game.
I'm not a programmer at all. I'm a 3D designer. And I'm trying to restore that basic functionality.

I've managed to create some sort of basic locomotion functionality. But now I'm stumbeled upon couple of things.. how to tie controller/helmet rotation to direction of movement?

I've managed to build up a script that gives some results to move using a stick... 




    --Controller based movement
    if leftController~=nil and self.walkMethod == 1 then
        self:controllerWalk()
    end

    --Update offset position
    local pos = VR:GetOffset()
    local d = self.targetoffset:DistanceToPoint(pos)
    local speed = 0.1 * self.teleportSpeed
    if leftController~=nil and self.walkMethod~=2 then
        speed = 0.01 * self.walkSpeed
    end
    if speed>d then speed=d end
    pos = pos + (self.targetoffset - pos):Normalize() * speed
    VR:SetOffset(pos)

 

function Script:controllerWalk()
    local playerMovement = Vec3(0)
    playerMovement.x = Math:Clamp(VR:GetControllerAxis(VR.Left, VR.TouchpadAxis).x, -1, 1)
    playerMovement.z = Math:Clamp(VR:GetControllerAxis(VR.Left, VR.TouchpadAxis).y, -1, 1)

    local controller = VR:GetControllerModel(VR.Left)
    local crot = controller:GetRotation(true)             --retrieve rotation values
    self.targetoffset = VR:GetOffset()+playerMovement*crot                    --shows that rotation values indeed are getting retrieved but movement direction in game applied in a weird way...
end

Im stumbeled on how to apply those values correctly so that if I hold stick up... player would move in a direction where controller is facing.
The same goes to helmet.. I assume I have to retrieve rotation values from the camera?

 

 

 

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