anissen Posted February 24, 2014 Share Posted February 24, 2014 I need my space ship to follow the rotation of the planet it lands on. See example below: My current approach is as follows:ship.position.x = planet.x;ship.position.y = planet.y;ship.pivot.set(planet.width);ship.rotation = planet.rotation;However, this results in the ship getting an incorrect position and rotation. See this (quite laggy) example. Ideally, I would like to be able to write: ship.pivot.set(planet.position); // rotate around this global positionship.rotation = planet.rotation;Any ideas? Quote Link to comment Share on other sites More sharing options...
Sebi Posted February 25, 2014 Share Posted February 25, 2014 Just a thought: When your ship lands and the planet is already at lets say 45° and you just copy that then the ship will be set at 45° too.It would make more sense if you increment the ships rotation by the same amount that you increment the planets rotation with. Quote Link to comment Share on other sites More sharing options...
xerver Posted February 25, 2014 Share Posted February 25, 2014 I think the easiest way to do this would be to put the planet and the ship in a container (DIsplayObjectContainer) and then rotate the container. xdiepx 1 Quote Link to comment Share on other sites More sharing options...
anissen Posted March 11, 2014 Author Share Posted March 11, 2014 I think the easiest way to do this would be to put the planet and the ship in a container (DIsplayObjectContainer) and then rotate the container. I tried it, but couldn't get it working. Luckily, it turned out to be pretty easy to handle the rotation "manually". Here's the gist of it: var planet = shipEntity.misc.landedOnPlanet; var rot = planet.position.rotation - shipEntity.misc.startRotation; shipEntity.position.rotation = rot - Math.PI / 2; shipEntity.position.x = planet.position.x - Math.cos(rot) * planet.sprite.radius * 1.2; shipEntity.position.y = planet.position.y - Math.sin(rot) * planet.sprite.radius * 1.2;whereshipEntity.misc.startRotation = entity.position.rotation - Math.atan2(planet.position.y - shipEntity.position.y, planet.position.x - shipEntity.position.x);Here's another laggy video: http://recordit.co/I8QzIw Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.