Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Aspect13 · Apr 16, 2019 at 12:31 PM · transform3dvector3shootingbullet

Move the bullet from the BulletEmitter in the direction player is facing 3D.

Hello, I want to make the bullet go from BulletEmitter which is already done but I want it to go IN THE DIRECTION MY PLAYER IS FACING. And this part is important I don't want to make it go forward forever:

transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime); //WRONG CODE, IT GOES ALWAYS FORWARD ALONG THE Z AXIS.
I tried literally everything. With Rigidbody the bullets are weirdly rotating though I instantiate them with Quaternion.Identity. Also I tried launching the bullet this way: transform.Translate(BulletEmitter.forward * moveSpeed * Time.deltaTime); //Same effect as the previous code.
I have no idea what to do. Please help me. I tried using MoveTowards() and move it towards my crosshair but still does not work:
Vector3.MoveTowards(transform.position, Crosshair.transform.position, maxDistance * moveSpeed * Time.deltaTime); //The bullet just stands still in the air...
If it's possible I would rather use Vector3 or transform to move the bullet instead of Rigidbody but Rigidbody is easier or better then okay. :/

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 Aspect13 · Apr 17, 2019 at 08:03 PM 0
Share

Help someone please.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Aspect13 · Apr 17, 2019 at 08:03 PM

FIXED IT! I just had to spawn the bullet with the same rotation as my Player was!

Instantiate(BulletPrefab, BulletEmitter.position, PlayerPrefab.transform.rotation);

The Update() with transform.Translate was fine:

transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);

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
0

Answer by NikitaDemidov · Apr 17, 2019 at 08:14 PM

Try this: If you want the bullet to follow the Player:

     class ClassInBullet
     {
     
     bool StopMove;
     public GameObject Player;
     
     void Start()
     {
     StartCoroutine(move());
     }
     IEnumerator move()
     {
     while(!StopMove){
     transform.position += (transform.position - Player.transform.position) / 10f;
    yield return new WaitForSeconds(0.1f);
     }
     }
     }

+This will let the tiles slower when they are nearer to the Player.

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 NikitaDemidov · Apr 17, 2019 at 08:42 PM 0
Share

I tried it and had to change the code to this

 void Start()
         {
             StartCoroutine(move());
 
         Destroy(gameObject,3f);
         }
 
         IEnumerator move()
         {
             while (!Stop$$anonymous$$ove)
             {
                 transform.position -= (transform.position - Player.transform.position) / 15f;
                 yield return new WaitForSeconds(0.08f);
             }
         }

It woked great. Here's a screenshot:I can't uplode it!? It doesn't stop to load.

If you want I can give you all the scripts.

avatar image Aspect13 NikitaDemidov · Apr 18, 2019 at 06:32 AM 0
Share

It doesn't work the bullets still go like if I wrote Vector3.forward...

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

168 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

Related Questions

Move the bullet from the BulletEmitter in the direction player is facing 3D. 1 Answer

I Want To Shoot Bullets Correctly. 2 Answers

Shooting script C# 1 Answer

How to change Vector3 if an objects rotation is a certain number? 1 Answer

Problem with Shooting Accuracy 0 Answers


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