Search Unity

Having some sort of world/space issue I think...Help appreciated

Discussion in '2D' started by naturebytes, Jun 22, 2019.

  1. naturebytes

    naturebytes

    Joined:
    Apr 24, 2019
    Posts:
    12
    Hi there, Hope all is well, Beginner here. Tried to debug for around 3 hours before I chose to seek help here. can't tell if its an engine issue or my code. So below are 3 pictures of my problem. I have a laser prefab for single shots and then a TripleShot powerup. My regular laser Instantiates just fine with 0 problems.

    My triple shot powerup is 3 lasers that are within a empty GameObject called Triple shot (Parent). The problem is that even though there is no offset in my code, the triple shot lasers are offset and whats stranger is the offset Changes depending on where my character is. If i go left, the offset goes right. Vice versa. And Its the same on the Y axis as well. If i go up the offset goes down.

    I can code in an offset when my ship starts the game at (0,0,0) but it doesn't matter as its changing based on player location. I've tried remaking triple shot. Restarting Unity.


    weird offset3.png Weirdoffset.png weirdoffset2.png

    Here is my code -

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class Player : MonoBehaviour
    {


    //variables

    [SerializeField] float speed = 5;
    [SerializeField] float fireRate = 0.5f;
    [SerializeField] int lives = 3;

    private float nextFire = 0.0f;

    [SerializeField] bool isTripleShotActive = false;

    [SerializeField] GameObject laserPrefab;
    [SerializeField] GameObject tripleShotPrefab;




    // cached references
    SpawnManager spawnManager;



    void Start()
    {
    transform.position = new Vector3(0, 0, 0);
    spawnManager = GameObject.FindObjectOfType<SpawnManager>();
    }


    void Update()
    {
    Movement();

    if (Input.GetKeyDown(KeyCode.Space) && Time.time > nextFire)
    {
    FireLaser();
    }
    }





    private void FireLaser()
    {

    nextFire = Time.time + fireRate;

    if (isTripleShotActive == true)
    {
    Instantiate(tripleShotPrefab, transform.position, Quaternion.identity);
    }
    else
    {
    Instantiate(laserPrefab, transform.position + new Vector3(0, .7f, 0), Quaternion.identity);
    }

    }
     
  2. Cathal111

    Cathal111

    Joined:
    Jan 5, 2017
    Posts:
    14
    Have you reset the transform of your Triple Shot Prefab so that the parent is at (0,0)?
     
  3. naturebytes

    naturebytes

    Joined:
    Apr 24, 2019
    Posts:
    12
    I did. Same result. Really scratching my head. Im looking at my code and it just doesn't make sense that its a code problem.
     
  4. naturebytes

    naturebytes

    Joined:
    Apr 24, 2019
    Posts:
    12
    Downloading newer 2019.1.7 There are some prefab fixes in there. I hope they fix the problem Im having.
     
  5. RustyPeacemaker

    RustyPeacemaker

    Joined:
    Aug 31, 2019
    Posts:
    1
    Did you figure it out? I am having the exact same issue and am totally stumped.
     
  6. Dragnnight

    Dragnnight

    Joined:
    Oct 12, 2019
    Posts:
    1
    I know this was a few months ago and you guys either moved on or fixed it. How ever I was having the same problem and read this thread and saw the post about resetting the transform of the prefab, and then I was like wait a minuet the empty game object I created for the parent of the lasers I never reset that transform. So all I did was delete the Triple shot prefab and and re due the triple shot, and when I created the empty game object I reset its transform before I dragged the lasers in there and it works perfectly now.
     
    chez63 and mathias_unity851 like this.
  7. mathias_unity851

    mathias_unity851

    Joined:
    Oct 18, 2019
    Posts:
    1
    Thank you! Had the same problem as all above and your method solve it for me as well.
     
  8. raviyadav4875

    raviyadav4875

    Joined:
    Dec 3, 2019
    Posts:
    1
    Hint was enough. Having similiar issue of lasers firing from different x for triple shot.
    I have actually not changed the transform of player and assign the lasers (tripleshot ) wrt wrong x,y of player so it was firing from wrong poisiton. Finally solved it.
     
  9. chez63

    chez63

    Joined:
    Nov 1, 2019
    Posts:
    2
    Awesome thanks so much this worked like a charm. It was staring me in the face lol