Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

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:
    Saturday
    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.