Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Epic_ · Jan 18, 2015 at 10:24 PM · transformspawnpointsgunfire

When I set spawn point to a transform, when I play it changes

When I play my transform changes and I have set the prefab to the same position to be sure, I am trying to make my bullet fire out of my gun barrel here is the script

using UnityEngine; using System.Collections;

public class Shooting : MonoBehaviour {

 public Rigidbody BulletPrefab;
 public float speed = 100f;
 
 // Update is called once per frame
 void Update () {
     if (Input.GetMouseButtonDown(0)){
     Rigidbody BulletInstance;
     BulletInstance = Instantiate(BulletPrefab, transform.position, transform.rotation) as Rigidbody;
     BulletInstance.AddForce(transform.forward * speed);
         }

     



 
 }

}

thanks!

Comment
Add comment · Show 4
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 Simon-Larsen · Jan 18, 2015 at 10:32 PM 0
Share

$$anonymous$$ake sure that "transform" is located at the gun muzzle.

avatar image superluigi · Jan 18, 2015 at 10:42 PM 0
Share

what exactly is the problem you are having?

avatar image Epic_ · Jan 19, 2015 at 10:26 PM 0
Share

$$anonymous$$y bullets spawn above my player even if I move the transform of my bullet spawn point

avatar image Epic_ · Jan 19, 2015 at 10:27 PM 0
Share

and my spawn is placed at the muzzle but it just spawn over my player

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by superluigi · Jan 18, 2015 at 10:46 PM

If I'm not mistaken, the final line of your code has it adding force to your bullet every Update and at the transform.forward of your gun and not the bullet. You should always handle physics such as addforce in fixedUpdate and not Update, and your line also means that when your player turns the bullet is gonna turn with it (because every frame it will = the forward of your gun instead of the forward of the bullet)

Comment
Add comment · Show 5 · 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 superluigi · Jan 18, 2015 at 10:48 PM 0
Share

are you shooting in first person view? If that's the case then when you look up, you might not see the bullet if your script isn't attached to the camera or something with the cameras rotation. Let me know so i can help you further and explain exactly what i mean

avatar image Epic_ · Jan 19, 2015 at 10:26 PM 0
Share

no im in third and it spawns above my player wherever I place it, thanks for answering though!

avatar image superluigi · Jan 20, 2015 at 06:07 AM 0
Share

ook so is your spawn point an empty game object? the fix is really quite simple. Separate your game view from your scene view, and make sure that you don't maximize your game view when you hit play. Now select your spawn point in the hierarchy and check if it's above your player when you hit play, also check if it moves with your player when he walks.

avatar image Epic_ · Jan 20, 2015 at 03:24 PM 0
Share

my spawn point is a sphere and I can move it to my barrel but it will just move back over my player when I hit play, also it moves with the player but it will move further away every second, I think it might be my animation because it makes my soldier move slightly every frame, it also wont shoot forward in front of my spawn point like it should be

avatar image superluigi · Jan 20, 2015 at 07:20 PM 0
Share

ok that's weird. I never apply root motion from animations to my characters, so i can't necessarily say if it leaves your transform alone while the character moves, but I doubt that's the case. There's absolutely no reason for the sphere spawn point to jump to the top of your character unless a script is telling it to do so. Check every code you have that references the sphere spawn point and look for the line where you're messing with it's transform.position. Also before you do that, real quickly turn off apply root motion on your character so that the animation doesn't move it's position, hit play and check if the sphere still jumps to the top of your character. Also try deactivating your animator if possible (might not be possible depending on your code) and check if it still does that. finally, while in play mode, in the scene view select and manually drag your character and check if the sphere follows your character

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Overlapsphere isn't working as expected. 0 Answers

Best way to move between maps 1 Answer

NullRef error 1 Answer

Instantiate Problem 2 Answers

How to create spawnPoint for bullet shoot 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