- Home /
Move along between two points
I have a sawblade and I can move it left/right or up/down, but I want to make it move accordingly to an angle. Or rotate the whole system, so it moves like up/down, but because it is rotated it will move diagonally. I believe there are tons of ways implementing this
This code I use for moving, and it works fine.
pos = transform.position;
yNow = transform.position.y;
pos.y = yNow + Time.deltaTime * liftSpeed * direction;
transform.position = pos;
Then if it hits a specific collider it moves onto another direction.
This is how it looks http://puu.sh/cv4DZ/1c7bb457f2.png I tried to rotate the whole structure like this http://puu.sh/cv4IT/837dc70018.png but, the blade still goes straight to the top, because it moves as Y being incremented
So basically all I want is to move the blade between those points, but I'm clearly missing something
Answer by Baste · Oct 29, 2014 at 05:04 PM
If you want to move the transform according to it's rotation, just use it's own up and right parameters, as they are relative to the transform's rotation. So, say you want to move your sawblade upwards relative to it's rotation, you do this:
transform.position += transform.up * Time.deltaTime * liftSpeed;
Hope that helps!
I figured it out: I parented my blade to an empty object and attached the script to it ins$$anonymous$$d of the blade, so the blade rotates and moves within this empty object
big thanks