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 Zitoox · Aug 09, 2016 at 05:35 PM · c#script.spawningspawning problemswrong

How to rotate an object

I have a problem with a script. I am making a FPS Game and i have a spawn bullet script. It's pretty simple, but it does what it was supposed to do. At least most of it...

I want to spawn a cilinder and then make it go, you know, like "fly, you are free". I am glad that everything works fine, except that it's pretty unconfortable to see your bullet fly inverted =|

When it spawn, it is inverted. Not that it goes backward, but it is pointed up, when it was supposed to be pointed to the sides. The image explains everything.

Here's my script:

 using UnityEngine;
 using System.Collections;
 
 
 public class ShootTime : MonoBehaviour {
 
          public Rigidbody projectile;
 
      public float speed = 0;
 public float fireRate = 0.5F;
 private float nextFire = 0.0F;
 void Update()
 {
     if (Input.GetButton("Fire1") && Time.time > nextFire)
     {
         nextFire = Time.time + fireRate;
         Rigidbody clone = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
         clone.velocity = transform.TransformDirection(new Vector3(0, 0, speed));
         }
 }
  }

What can i do to change the bullet so it spawn like... A BULLET. And still nothing changes in it's aerodynamics/direction? alt text

uaf.png (395.4 kB)
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

· Add your reply
  • Sort: 
avatar image
0

Answer by TheShadyColombian · Aug 09, 2016 at 05:51 PM

Recreate your prefab as an empty, which has your 3D model as a child. Rotate the child (the 3D model), not the parent (the empty), how you want, and then use a prefab of the whole thing as your bullet.

Comment
Add comment · Show 3 · 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 Zitoox · Aug 09, 2016 at 08:24 PM 0
Share

Have you actually read the script? It requires a GameObject with physics. Did you know that? I don't think i will be able to throw an empty game object at it, and change the script would take time that i don't have =/

avatar image TheShadyColombian Zitoox · Aug 09, 2016 at 08:32 PM 0
Share

so keep all physics components (rigidbody, collider) on the empty, and all graphic components (mesh, $$anonymous$$eshRenderer) in the child object.

avatar image Zitoox TheShadyColombian · Aug 09, 2016 at 11:57 PM 0
Share

Still, i don't believe it will work, but i will give it a try.

avatar image
0

Answer by sambid123sameer · Aug 09, 2016 at 06:56 PM

I guess you are using a prefab for the bullet?

Take the prefab in the scene and make sure the Blue arrow (Z Axis) is pointing the correct direction and rotation you want the bullet to go

Example something like this :-

alt text

alt text

if not then you have to make a new bullet with the blue (Z Axis) pointing correct direction

Im saying 'Z' here because in your script , in the vector3(X,Y,Z) you have set the speed variable on the Z position (0,0,speed) which is X=0 , Y=0 , Z = Speed variable

P.S Sorry for my noob explanation :P


screen-shot-2016-08-09-at-111750-pm.png (27.9 kB)
screen-shot-2016-08-09-at-111805-pm.png (29.7 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 Zitoox · Aug 09, 2016 at 08:18 PM 0
Share

@sambid123sameer

I know that, it's correct. It doesn't change anything.

avatar image sambid123sameer Zitoox · Aug 10, 2016 at 11:26 AM 0
Share

it should work lol

can i see your bullet prefab? drag it into the scene and letme see it

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

203 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

Related Questions

Applying Scripts held in a list to a game object 1 Answer

Items spawn and will not stop spawning. 2 Answers

Problem with Random Spawning 1 Answer

Spawn system that doesn't instantiated enemies on top of player or each other (C#) 2 Answers

Avoid changes if I dont changing my position. 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