povdocs / webvr-starter-kit

Other
298 stars 59 forks source link

can't get current position of an object via code #7

Closed skompc closed 9 years ago

skompc commented 9 years ago

hi, im trying to make a game that supports physics and collision without needing any other external libraries, and im stuck on getting the objects position... heres some example code so you can see what im trying to do...

    var sphere = VR.sphere()
      .setMaterial('metal')
      .setScale(1.4)
      .moveTo(1, 9, 2);

    var spherePosX = sphere.x //get X position of sphere 
    var spherePosY = sphere.y //get Y position of sphere
    var spherePosZ = sphere.z //get Z position of sphere

i know the above code is wrong, but idk what to put in place of 'sphere.x', 'sphere.y', and 'sphere.z' please help me!

skompc commented 9 years ago

i just found the answer to my own question by going through the source code... code should be as follows for anyone who needs it:

var sphere = VR.sphere()
  .setMaterial('metal')
  .setScale(1.4)
  .moveTo(1, 9, 2);

var spherePosX = sphere.object.position.x //get X position of sphere 
var spherePosY = sphere.object.position.y //get Y position of sphere
var spherePosZ = sphere.object.position.z //get Z position of sphere

put a '.toString()' at the end if you need to display it on screen through a text object

brianchirls commented 9 years ago

Great. Glad it worked out.