I am making a spike which pops a needle every t interval. I am able to make this to work. But when I try to rotate my game object, say, sideways leftwards, the popping of needle literally goes up and down not sideways as I expect. I need it to move up and down on an axis. Currently, in my game the game object is facing the green line (y-axis). I want my needle to go up and down on this axis.
What I am expecting is that the needle to pop out leftwards, since I made it face leftwards (via rotation)! I can circumvent this by making an object and appropriate scripts but that is very stupid and rubbish.
I think the problem is that you set your vectors relaxed and poped only once during start method. When you rotate your object update those vectors too.
I believe I don’t have to? I want it to move to a specific axis. To its local axes. I was able to make this to work by using
this method transform.Translate. But it goes on and on without stopping.
Thanks, actually I gave up, it doesn’t fit quite well into the game so I decided to ditch the idea. Thanks you very much! I look into it when I come back to that idea again. Maybe I am able to make this work next time.
As I said just recalculate relax and popped when rotating.
Firstly you can simplify those lines:
relax = transform.localPosition;
popped = relax + transform.up * 0.8f;
And make sure they get updated, so put them in to your PopNeedles() coroutine.
It works