- Home /
Comparing to a relative position.
This should be an easy question, but I'm having trouble with it.
I'm working in a 2D field, with a space ship type game object that is player controlled. There are engines on the side of the ship, and they work fine so far, apart from the controls. See, when the player presses left to rotate the ship left, the engines on the right need to turn on, while the engines on the left stay off, in order to rotate the ship. The deal is, since the ship is player generated, I need to find out which side the engine is on, and since the ship can turn, I can't use world space.
Long story short, how can I find out if this object is on the left or right relative to the ship only?
Answer by Eric5h5 · Nov 09, 2010 at 03:18 AM
if (transform.InverseTransformPoint(engineTransform.position).x > 0.0) {
// right
}
else {
// left
}
Thanks a lot! Haven't tried it yet, but 99% sure that will work. You've been a great help!
Your answer
Follow this Question
Related Questions
how to have an object positioned relative to the screen(like a button) 1 Answer
gui position of Screen relative position 2 Answers
Find Distance on Single, Relative Axis? 1 Answer
Object coordinates relative to camera 2 Answers
How do I get a RectTransform position relative to another that is not the parent? 0 Answers