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 /
This question was closed Jan 09 at 09:00 PM by Silver195 for the following reason:

Other

avatar image
0
Question by Silver195 · Mar 02, 2021 at 12:04 PM · movement scriptbullets

How do I get by bullet clone to move forward when mouse is clicked?

(I'm still very new to Unity) I've tried making it so the bullet would move forward when the mouse is clicked. But when I test it, the bullet clones spawn and don't move. The bullets properly go to the player and appear like I want it to but it doesn't move forward like I want it to. The code I used originally came from a Brackeys video. It was for 2D top down shooter tutorial. I did every step correctly but only from the shooting part but it didn't work. The function of his game was different from mine because his character would follow the mouse and my character just faces forward. But when I tested I originally tried the "firePoint.up" part into the script, like in the tutorial, and that made the bullet go up instead of forward. So I thought instead I could change it to "firePoint.forward". But when I tested it, the bullet just appeared and did nothing. I have all the code used if it is needed to help me out but I want to know what to do to fix this. I just want it so when the mouse is clicked, the bullet moves forward and deletes when it touches an object.

Comment
Add comment
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

2 Replies

  • Sort: 
avatar image
1

Answer by deckerjoshua239 · Mar 02, 2021 at 04:16 PM

Make sure to assign everything to where it needs to be and you can delete the particle stuff if you do not know how to make a particle. I did not make this script this guy did. Brackeys:https://www.youtube.com/brackeys

using UnityEngine;

public class Guns: MonoBehaviour {

 public float damage = 10f;
 public float range = 100f;
 public float fireRate = 15f;
 public float impactForce = 30f;

 public Camera fpsCam;
 public ParticleSystem muzzleFlash;
 public GameObject impactEffect;

 private float nextTimeToFire = 0f;





 // Update is called once per frame
 void Update()
 {
    if (Input.GetButton("Fire1") && Time.time >= nextTimeToFire)
     {
         nextTimeToFire = Time.time + 1f / fireRate;
         Shoot();
     }
 }

 void Shoot ()
 {

     muzzleFlash.Play();
     RaycastHit hit;
     if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
     {
         Debug.Log(hit.transform.name);

         Target target = hit.transform.GetComponent<Target>();
         if (target != null)
         {
             target.TakeDamage(damage);
         }

         if (hit.rigidbody != null)
         {
             hit.rigidbody.AddForce(-hit.normal * impactForce);
         }

         GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
         Destroy(impactGO, 1f);
     }
 }

}

Comment
Add comment · 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
1

Answer by $$anonymous$$ · Mar 02, 2021 at 05:33 PM

Check if your character's facing forward sprite matches in the forward direction of the transform, and not the right / left.


If not, change 'firePoint.forward' to 'firePoint.right' if facing right, or throw a minus in front of it and use '-firePoint.right' for the left.


alt text


untitled.png (280.4 kB)
Comment
Add comment · Show 2 · 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 Silver195 · Mar 02, 2021 at 10:03 PM 1
Share

It worked! Thanks so much for your help.

avatar image $$anonymous$$ Silver195 · Mar 04, 2021 at 05:36 PM 0
Share

Anytime bro

Follow this Question

Answers Answers and Comments

117 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

Related Questions

How to move an object to a certain direction using arrow keys? 1 Answer

How do I add camera rotation while moving a player sideways? 2 Answers

How can make the player move constantly when the key A or D is held down? 1 Answer

Player walks in the direction the vr camera is looking? 2 Answers

Lift Movement 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