Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Character position not returning the correct position

Discussion in 'Scripting' started by Ronni_Boni, Oct 8, 2023.

  1. Ronni_Boni

    Ronni_Boni

    Joined:
    Dec 19, 2022
    Posts:
    4
    HI I have a problem while trying to get a game object to be in the same position as the character (its not a child of it) but it ends up going to one random fixed position in the map without changing as the character move. I tried using local and global position but it still gave a fixed position

    Code (csharp):
    1.  
    2. protected override void Update()
    3. {
    4. print(character.transform.position);
    5. if(released)
    6. {
    7. body.velocity = new Vector2 (AttackSpeed * Facing,Mathf.Sin((Time.time - start_time) * Vertical_V)* Current_amplitude);
    8. }
    9. else
    10. {
    11. transform.position = new Vector2 (character.transform.position.x + (gap * Facing), character.transform.position.y);
    12. }
    13. }
    14. }
    15.  
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    6,015
    Check if you're referencing perhaps the player prefab's position (the one in your assets), and not the actual live instance in the scene.
     
  3. Ronni_Boni

    Ronni_Boni

    Joined:
    Dec 19, 2022
    Posts:
    4
    Ohh that was indeed the problem, I managed to solve it thank you!
     
    spiney199 likes this.