Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by kaden1023 · Mar 16, 2021 at 04:21 PM · physicsvector3bulletgun

bullet doesn't go anywhere

I made the following script and attached it to my gun, which has a child that is located at the barrel named launch. using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Shoot : MonoBehaviour {

private float shootTimer; public float fireRate; [SerializeField] private GameObject launch; [SerializeField] private GameObject bullet; private Vector3 launchLocation;

 void Start()
 {
     fireRate = 0.5f;
     launchLocation = launch.transform.position;
 }

 // Update is called once per frame
 void FixedUpdate()
 {
     if(Input.GetMouseButton(0))
     {
         if(shootTimer < 0.1f)
         {
             Instantiate(bullet, launchLocation, Quaternion.identity);
             shootTimer = fireRate;
         }
         else{
             shootTimer = shootTimer - 0.1f;
         }
     }
 }

}

Then I have the bullet as a prefab that the gun Instantiates that has this script: using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Bullet : MonoBehaviour { [SerializeField] private float speed; [SerializeField] private float startz; [SerializeField] private float currentz; [SerializeField] private float range; void Start() { startz = transform.position.z; speed = 10f; }

 // Update is called once per frame
 void FixedUpdate()
 {
     transform.position += new Vector3(0,0,1);
     currentz = transform.position.z;
     if(currentz > startz + range)
     {
         Destroy(this);
     }
 }

} now, this spawns the bullets stacked on the ground and they don't move at all. This is a early version of the game and this is just about the only thing in the scene besides a capsule representing the player and a camera, well, being a camera. Pls Help. Btw, the serialize field is for debug and won't always be there if that helps.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image logicandchaos · Mar 17, 2021 at 01:10 PM 1
Share

it sounds like your bullet has a rigid body on it, in that case you should be moving it by adding velocity not changing position. Also you can use Vector3.Distance or Destroy(this, inXSeconds); instead of using currentz

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by judahcline · Mar 17, 2021 at 05:05 PM

brackeys does a good job of describng it here: https://www.youtube.com/watch?v=wkKsl1Mfp5M

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kaden1023 · Mar 17, 2021 at 08:39 PM 0
Share

Thx I'll take a look here soon!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

208 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Calculating 3D Physics Prediction of Shot Direction with Moving target and moving gun (inertia) 1 Answer

bullet desent seem to apear (javascript) 0 Answers

Bullet does not move forward after being initiated 1 Answer

Vector3.Reflect problems 4 Answers

Shooting. Bullet floats and sprays 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges