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.
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.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public partial class Mover : MonoBehaviour{
public float speed;
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
rb.velocity = transform.forward * speed;
}
}
using UnityEngine;
using System.Collections;
[System.Serializable]
public class Boundary
{
public float xMin, xMax, zMin, zMax;
}
public class PlayerController : MonoBehaviour
{
public float speed;
public float tilt;
public Boundary boundary;
private Rigidbody rb;
public GameObject shot;
public Transform shotSpawn;
public float fireRate;
private float nextFire;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
if (Input.GetButton("Fire1") && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
}
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.velocity = movement * speed;
rb.position = new Vector3
(
Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
0.0f,
Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax)
);
rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt);
}
}
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…
Try increasing the speed value in the script. Find a value that works for you.
I increased value to 200, still lagy but move faster.
How can I profile my game?
BTW my ship move perfect
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.
New genre? Do you have to yell into your microphone to fire?
I profiler my game, the biggest ms used is from Gfx.WaitForPresent with 70-80 self ms
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.
I did it, but noone helped me
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.
Mind if I ask what it is that you did?
I asked about this problem on Space Shouter tutorial Q & A topic but nobody helped me. This is why I created another post
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?
Mass:1
Drag: 0
Angular Drag:0.05
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.
the same effect, bullet is still slow