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 muntahu · Oct 30, 2010 at 03:05 AM · rotationinstantiatebullet

Modify the rotation of Instatiate prefab

I want to make an instantiation of bullet which direction is depend on mouse-y, so the y-direction of bullet can be changed according to the mouse-y. Can anyone help to modify my current code? i think the problem is in the transform.rotation. Thanks^^

        var instantiatedProjectile : Rigidbody = Instantiate(projectile, transform.position, transform.rotation);
        //set direction of bullet to move forward through z axis of world coordinate
        instantiatedProjectile.velocity = transform.TransformDirection(Vector3(0, 0, speed));

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

Answer by lhk · Oct 30, 2010 at 08:12 AM

As far as I see it, you're instantiating the bullet from your player gameObject. I assume you're making some kind of First Person Shooter where you turn your character with the mouse. Therefore your characters rotation should be appropriate for the bullet and you needn't rotate the projectlile after instantiation. However to answer your question:

If you have the rotation you would like the bullet to have, then you can simply use

var instantiatedProjectile : Rigidbody = Instantiate(projectile, transform.position, desiredrotation);

If you want to rotate the object after instantiation you can add this line of code

instantiatedProjectile.transform.Rotate(anglex,angley,anglez);

Additionally you need to change the second line of your code.

 instantiatedProjectile.velocity = instantiatedProjectile.transform.TransformDirection(Vector3(0, 0, speed));

If you want to constantly change the rotation of your bullet, you need a seperate script. This script should be added to the projectile prefab. It may look like this:

var turnspeed : float;

function Update () {

 transform.Rotate(0,Input.GetAxis("Mouse X")*Time.deltaTime*turnspeed,0);

}

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 muntahu · Oct 31, 2010 at 03:36 AM 0
Share

var instantiatedProjectile : Rigidbody = Instantiate(projectile, transform.position, desiredrotation);

in this case, i want to make the desiredrotation according to the mouse-Y. So, the crosshair can be up and down, and if it's up/down, then the bullet will be launched to that crosshair's position. How do i do that?

Anyway, thanks for replying. it's very helpful.thanks.

avatar image lhk · Oct 31, 2010 at 08:29 AM 0
Share

I don't quite understand what you want to do. Do you have a problem in displaying a crosshair, making your character look up and down, or shooting a bullet ?

avatar image muntahu · Oct 31, 2010 at 11:17 AM 0
Share

let me clarify it. basically my problem is about shooting a bullet. I already can shoot. but it doesn't go according to the crosshair. it just goes forward z-axis. the crosshair is actually in the center of the screen as like 1st person shooter. So, maybe the problem is to synchronize the bullet direction with crosshair. is it clear enough? sorry if my words is hard to be understood.

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

No one has followed this question yet.

Related Questions

Instantiate rotation not working 1 Answer

Turret bullet rotation problem 1 Answer

Shoot an object and have it move based on rotation 1 Answer

Gun Projectile Shooting In Wrong Direction (Javascript) 1 Answer

Instantiate an image, equally in a circle and rotate it away from the center? 2 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