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 /
  • Help Room /
avatar image
0
Question by Korge · Jan 20, 2016 at 12:35 AM · 2dpositionshipshot

How can i change the position of my shot ?

Hi all,

One more yeah, i'm a newbee.

I'm following a tutorial to make my first shotgame 2D but i'm trying to understand the details of the scripts.

Actually i've a ship which can fire ammo. The part of the creation of the ammo is this :

 // Assign position
             shotTransform.position = transform.position;
             shotTransform.position += new Vector3(1.1f, 0, 0);

To be clear, the shotTransform is my ammo and the transform is just a component of my Player 1. Actually there is no problem to fire but the ammo starts since the middle of my ship. So i tried to add a horizontal vector to make it starts from the right side of my ship !

So actually i'm stucked here... Someone can tell me why my ammo starts again in the middle ? (1.1 is the distance betwen right side and the middle of the ship)

Thank you for your help and have a good week ! :p

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

1 Reply

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

Answer by incorrect · Jan 20, 2016 at 12:35 AM

Please, format the code using Markdown Syntax.

Your shots are fired from the point transform.position, so it's the point where transform of an object you have attached this script is placed at the moment. If it's attached to the ship, this will result in getting ship's position.

To make it work a bit more natural I'll suggest doing so:

Add an empty GameObject to your ship as a child and place it somewhere you want your shot to be fired from.

After that add this lines to the script:

 [SerializeField]
 private Transform firingPoint;

What they actually are doing is adding a reference to some Transform which is not accessible with other scripts due to 'private' modifier, but can be assigned in Inspector by drag'n'dropping. So place your newly created firing point there.

And after that to fire you have to place the shot in that point:

 shotTransform.position = firingPoint.position;

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 Korge · Jan 21, 2016 at 01:01 PM 0
Share

Hi Incorrect,

Thank you for your tips with the child. I've had little difficult to find the transform.Find("firingPoint").position but it works ! :D

avatar image incorrect Korge · Jan 21, 2016 at 06:44 PM 0
Share

What I suggest is not using transform.Find("firingPoint"), but to assign it using Inspector.

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

57 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

Related Questions

Collider and Rigidbody Problem 1 Answer

keep a 2d sprite in an area via color 0 Answers

Position changing though set position code running 1 Answer

iscometric grid panning 0 Answers

Game Object doesn't instantiate at Mouse Position 3 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