- Home /
Having difficulty with Parent Object rotation and Child Object movement.
So in my game, I plan to have entities move around inside of space ships that rotate and move themselves. To this end I've been experimenting with pathfinding. Currently it is set up where the grid is a component of the parent object, and parts of the ship have nodes that link itself to the grid and these are children etc. This all works really well on the whole...so long as the ship stays still. The little NPC circle I have stops moving if the rotation of the parent is any number other than 0. Setting the parent's rotation to 0 fixes this and the circle continues on its merry way. The method that follows te waypoints is as follows:
IEnumerator FollowPath() {
Node currentWaypoint;
targetIndex = 0;
while (transform.localPosition != currentPath.end.localPosition) {
currentWaypoint = currentPath.waypoints [targetIndex];
if (transform.position == currentWaypoint.localPosition) {
targetIndex++;
currentWaypoint = currentPath.waypoints [targetIndex];
} else {
transform.localPosition = Vector2.MoveTowards (transform.localPosition, currentWaypoint.localPosition, speed * Time.deltaTime);
}
yield return null;
}
Debug.Log ("Path complete!");
}
I feel as though this problem stems from my use of the Vector2.MoveTowards() method. Thanks for any assistance.