Hey guys. Not sure if this belongs in scripting or support, feel free to move the topic.
So i have in my game a script that allows me to instantiate a turret prefab, by clicking the mouse. The script raycasts from the center of the screen, and returns the point of intersection with the ground as the position of instantiation. That part of the script is seen here:
if (Input.GetButtonDown("Fire1")){
RaycastHit hit;
if (Physics.Raycast (Camera.main.transform.position,Camera.main.transform.forward, out hit,1000)) {
_position = hit.point;
Object tower;
if(mTurret == true){tower = Instantiate(mturret, _position, Quaternion.identity);
//Reset the Machinegun Turret bool
mTurret =! mTurret;
//return to idle state
playerState = PlayerState.idle;
}
The problem is, that the turret prefab keeps instantiating halfway through the floor as seen in this picture:
Red circle is how the turret is supposed to stand. yellow circle is how it actually stands
So i tried a few things:
-put a rigidbody on the turret prefab. didnt help
-Put a box collider around the prefab. didnt help
-moved the pivot of the model just down below the base plate. didnt help.
Im running out of ideas here, any tips?
thanks ![]()
