Search Unity

Space Shouter problem.... again

Discussion in 'Getting Started' started by Tempest74, May 24, 2017.

  1. Tempest74

    Tempest74

    Joined:
    May 17, 2017
    Posts:
    133
    Hello guys i come with another problem about space shouter tutorial. My shots move very slowly and laggy. It is beacouse of my PC or is another problem? I have a bad one.
    By the way thee speed of shots are 20. Do you need my codes? they are the same like in video but with modify for Unity 5.
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    You could definitely post the relevant code parts and from that, most probably get some feedback about how/if the code can be improved so that it's faster and/or less laggy.. :)

    Please use code tags/insert code properly. If you're not sure how to do that, there is a pinned thread in the forums with info.
     
  3. Tempest74

    Tempest74

    Joined:
    May 17, 2017
    Posts:
    133
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public partial class Mover : MonoBehaviour{
    6.     public float speed;
    7.  
    8.     private Rigidbody rb;
    9.     void Start()
    10.     {
    11.         rb = GetComponent<Rigidbody>();
    12.         rb.velocity = transform.forward * speed;
    13.     }
    14.    
    15. }
    16.  
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [System.Serializable]
    5. public class Boundary
    6. {
    7.     public float xMin, xMax, zMin, zMax;
    8. }
    9.  
    10. public class PlayerController : MonoBehaviour
    11. {
    12.     public float speed;
    13.     public float tilt;
    14.     public Boundary boundary;
    15.     private Rigidbody rb;
    16.  
    17.     public GameObject shot;
    18.     public Transform shotSpawn;
    19.     public float fireRate;
    20.  
    21.     private float nextFire;
    22.     void Start()
    23.     {
    24.  
    25.         rb = GetComponent<Rigidbody>();
    26.     }
    27.     void Update()
    28.     {
    29.         if (Input.GetButton("Fire1") && Time.time > nextFire)
    30.         {
    31.             nextFire = Time.time + fireRate;
    32.             Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
    33.         }
    34.     }
    35.  
    36.     void FixedUpdate()
    37.     {
    38.         float moveHorizontal = Input.GetAxis("Horizontal");
    39.         float moveVertical = Input.GetAxis("Vertical");
    40.  
    41.         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    42.         rb.velocity = movement * speed;
    43.  
    44.         rb.position = new Vector3
    45.         (
    46.             Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
    47.             0.0f,
    48.             Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax)
    49.         );
    50.  
    51.         rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt);
    52.     }
    53. }
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    So the mover is your bullet? That code seems very simple, straightforward and should just operate normally.
    Can't help you more with just that.. sorry :(
    Is the ship laggy, too?

    You could try to profile your game and see if something is wrong (spikes or something in the performance -- maybe pc/other code I didn't see).

    Sorry, man, hope you find a solution.
    post some follow up if you have any..
     
  5. Bill_Martini

    Bill_Martini

    Joined:
    Apr 19, 2016
    Posts:
    445
    Try increasing the speed value in the script. Find a value that works for you.
     
  6. Tempest74

    Tempest74

    Joined:
    May 17, 2017
    Posts:
    133
    I increased value to 200, still lagy but move faster.
    How can I profile my game?
     
  7. Tempest74

    Tempest74

    Joined:
    May 17, 2017
    Posts:
    133
    BTW my ship move perfect
     
  8. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
  9. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Ya, try the profile, can't hurt. If your ship is good, I'm not sure what is wrong with bullets. At least you got the speed part.
     
  10. Steve-Tack

    Steve-Tack

    Joined:
    Mar 12, 2013
    Posts:
    1,240
    New genre? Do you have to yell into your microphone to fire? :D
     
  11. Tempest74

    Tempest74

    Joined:
    May 17, 2017
    Posts:
    133
    I profiler my game, the biggest ms used is from Gfx.WaitForPresent with 70-80 self ms
     
  12. Bill_Martini

    Bill_Martini

    Joined:
    Apr 19, 2016
    Posts:
    445
    I'm thinking profiling your game is not the answer. Learning how to interpret the profiler is a skill like any other part of Unity. And there is a good chance the profiler will not reveal any revenant information regarding your problem.

    Start looking at the bullet object. Is drag set improperly in the Rigidbody component? Make sure all settings match the tutorial. The original speed will probably work when you correct the problem.

    Lastly, and you should have been directed there in the first place, the tutorials have their own forums. Someone there is more familiar with that tutorial and is more likely to help you out. If my suggestions above don't help, go there to get proper help.
     
  13. Tempest74

    Tempest74

    Joined:
    May 17, 2017
    Posts:
    133
    I did it, but noone helped me
     
  14. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    True, I sometimes forget about those specific tutorial forums.
    It's good advice to double check the bullet's rigidbody settings, though.

    If mostly everything else is working, and for whatever reason you're still stuck with slightly silly bullets, just check everything and then keep going with what you're doing. You can always come back to this later for some polish.
     
  15. FerretInABox

    FerretInABox

    Joined:
    Jun 18, 2015
    Posts:
    5
    Mind if I ask what it is that you did?
     
  16. Tempest74

    Tempest74

    Joined:
    May 17, 2017
    Posts:
    133
    I asked about this problem on Space Shouter tutorial Q & A topic but nobody helped me. This is why I created another post
     
  17. FerretInABox

    FerretInABox

    Joined:
    Jun 18, 2015
    Posts:
    5
    Ah okay, my bad. I didn't know you were working with the actual Space Shooter tutorial. Did you make sure the Bolt Prefab had the correct rigidbody settings in the Inspector?
    Code (csharp):
    1. Mass:1
    2. Drag: 0
    3. Angular Drag:0.05
     
  18. Tempest74

    Tempest74

    Joined:
    May 17, 2017
    Posts:
    133
    upload_2017-5-26_9-45-24.png
    Ignore the asteroid, I am working at the game now, you can see my bolt setings
     
  19. FerretInABox

    FerretInABox

    Joined:
    Jun 18, 2015
    Posts:
    5
    Well just a heads up, your Direction in the capsule collider is along the wrong axis if you're following the tutorial word for word. It has the direction moving along the Z axis rather than the Y axis.

    That's the only thing I've noticed was off from the finished Prefabs and scripts for the tutorial.

    Does your computer stutter when testing the game out? If the bullet is just slow and everything else is moving fine, then it's definitely not a hardware issue on your part.
     
  20. Tempest74

    Tempest74

    Joined:
    May 17, 2017
    Posts:
    133
    the same effect, bullet is still slow
     
  21. FerretInABox

    FerretInABox

    Joined:
    Jun 18, 2015
    Posts:
    5
    Alright, how about a list of everything you've tried so far? That might help out a bit since I've compared each line of your code and inspector settings against the finished scripts.
     
  22. Tempest74

    Tempest74

    Joined:
    May 17, 2017
    Posts:
    133
    I tried only two thing to add instead of velocity AddForce but i dont realize how to exactly use is and nothing happened. Second thing i tried was to makr bullet more faster and then i realise them hitboxes move normaly. So hitboxes move always normaly but the shots body are laggy