Hey So I’m having an issue with this. I’m trying to change my gun position when the player runs.
I made a little script to start doing this but not sure how to implement it so the changes to the position I want and moves with the parent “player” object? Currently if i try and change the gun position to something else, when I start moving the gun ends up in a weird position behind the player. I move the gun while the game is running, get the positions, then try and add them to the script
public class GunPosition : MonoBehaviour
{
//weapon object
public GameObject gameObj;
//Attaching playermovement script to use it's varables
public playermovement Player;
// Start is called before the first frame update
void Start()
{
//weapon start position
gameObj.transform.position = new Vector3(0.1349f, 0.1358f, 0.3093f);
transform.localPosition = new Vector3(0.1349f, 0.1358f, 0.3093f);
}
// Update is called once per frame
void Update()
{
if (Player.moveDirection != Vector3.zero) //when player is moving, change gun position
{
//Example
gameObj.transform.position = new Vector3(1.0f, 1.0f, 1.0f);
transform.localPosition = new Vector3(0.1349f, 0.1358f, 0.3093f);
}
}
}