I’m creating a drone for my player that will launch from their back.
When activating the drone, the player’s camera is disabled and the drone’s camera is enabled.
The drone’s camera clips into the players back which is unacceptable. To stop this happening I created a method that will ‘launch’ the drone from above their head, with a Raycast checking above them incase of an obstacle.
Here is the launch code from the Drone script:
void launch(){
Vector3 launchPos;
RaycastHit hit;
if(Physics.Raycast(transform.position, Vector3.up, out hit, maxLaunchHeight)){
launchPos = hit.point;
launchPos.y -= 0.25f;
} else {
launchPos = transform.position;
launchPos.y += maxLaunchHeight;
}
Debug.Log("before: "+transform.position);
transform.position = launchPos;
Debug.Log("after: "+ transform.position);
}
The problem I am having is that updating transform.position does not actually change the position of the object; it is not raised above their head upon activation.
I can see through debugging that transform.position.y is being changed to the desired value but it doesn’t appear it is actually being applied to the object.
Strangely, I can change transform.position in the Update method - to help debug I added a bool that if true would set the position to some vector and when setting it to true mid-game it moves the drone to that vector without issue.
Any ideas as to why this might be happening?
If there is not enough info please let me know and I’ll be happy to post more code / try and explain it better.