Some basic script questions
Posted: 23.10.2005, 18:53
I've been playing around with some of the scripts from the Celestia wikibook ( http://en.wikibooks.org/wiki/Simple_CELX_Scripting ) and have come up with this to get the distance between Cassini and the observer:
To test it out, I selected Cassini and went to it (actually I set a distance of 1 km so I could verify the distance easily), so it's centred on the screen. When I run the code however, Cassini disappears - it seems that the direction the camera is facing suddenly changes for no apparent reason when I run the script (the distance stays the same so I know the camera isn't actually moving in space), and it doesn't seem to be looking at the same point each time. In fact this viewpoint shift happens whenever I run the script, regardless of what I'm looking at at the time.
Anyone know what's going on? How do I keep the view centred on whatever I'm looking at?
Also, I thought the default measurement for Celestia was the somewhat arcane "microlightyear"? If so, why does this script give results in kilometres? (not that I'm complaining, I prefer km by far. Just wondering what's going on).
Code: Select all
camera = celestia:getobserver()
cassini = celestia:find("Cassini") -- finds object named Cassini
cameraPosition = camera:getposition() -- gets position of observer
cassiniPosition = cassini:getposition() -- gets position of Cassini
distance = cassiniPosition:distanceto(cameraPosition) -- gets distance from position of Cassini to that of observer
celestia:flash("Current distance to Cassini is "..distance.. " km")
To test it out, I selected Cassini and went to it (actually I set a distance of 1 km so I could verify the distance easily), so it's centred on the screen. When I run the code however, Cassini disappears - it seems that the direction the camera is facing suddenly changes for no apparent reason when I run the script (the distance stays the same so I know the camera isn't actually moving in space), and it doesn't seem to be looking at the same point each time. In fact this viewpoint shift happens whenever I run the script, regardless of what I'm looking at at the time.
Anyone know what's going on? How do I keep the view centred on whatever I'm looking at?
Also, I thought the default measurement for Celestia was the somewhat arcane "microlightyear"? If so, why does this script give results in kilometres? (not that I'm complaining, I prefer km by far. Just wondering what's going on).