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 /
This question was closed Nov 29, 2014 at 08:12 AM by RedDevil for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by RedDevil · Nov 28, 2014 at 01:46 PM · rotationaddforceshootinganglesforward

2D Shooter - shooting forward at the current rotation

Hi! So I have a script where i rotate an enemy to face the player.Then I want the enemy to shoot a projectile at the angle the enemy is.I have tryed alot of different codes from the internet to shoot the projectile forward but instead my projectile does not move at all.

this causes the same thing: "rigidbody2D.AddForce(Vector3.forward Speed)" I also tryed rigidbody2D.AddForce(transform.forward Speed)" In both cases the projectile does not move. Any help is apreciated.Thank you

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 Stealthygolem · Nov 28, 2014 at 02:01 PM 0
Share

Have you tried changing

 rigidbody2D.AddForce(Vector3.forward Speed)

to

 rigidbody2D.AddRelativeForce(Vector3.forward Speed)


I don't know how it works with Vector3.forward. but I've used something similar with an x variable for adjusting (projectileSpeed).

avatar image RedDevil · Nov 28, 2014 at 02:04 PM 0
Share

same result

avatar image Stealthygolem · Nov 28, 2014 at 02:07 PM 0
Share

Take a look at my code for a projectile shooting thing:

         GameObject Clone;
         Clone = (Instantiate (bulletPrefab, transform.position, transform.rotation)) as GameObject;
         Clone.rigidbody2D.AddRelativeForce (new Vector2 (-bulletSpeed, 0));

If I change it to only AddForce, it only shoots in the same direction. Teh AddRelativeForce makes it so that the X-value is proportional to the rotation.

avatar image RedDevil · Nov 28, 2014 at 02:10 PM 0
Share

the problem is that i want it to go on the Z direction and if i just use forward it does not move at all

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by Stealthygolem · Nov 29, 2014 at 12:02 AM

Playing around with my code and his own variation, RedDevil accepted this collaborated code as an answer:

  rigidbody2D.AddRelativeForce(new Vector3 (0,Speed));

I'm glad I could help, even though you did most of the work!

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 RedDevil · Nov 28, 2014 at 02:27 PM

alright i made it work by modifying your code: here is the final one:

  rigidbody2D.AddRelativeForce(new Vector3 (0,Speed));


Submit that code as answer and i will accept it. Thank you

Comment
Add comment · Show 1 · 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 Stealthygolem · Nov 28, 2014 at 11:59 PM 0
Share

Ah, thank you. Though, you made it yourself!

Follow this Question

Answers Answers and Comments

27 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

Related Questions

Rigidbody.addforce then rigidbody.rotation and movement along transform.forward 2 Answers

raycast is pointing in two directions? 1 Answer

Roll a ball camera problem? 1 Answer

How would I go about finding the rotation corrresponding to the force added to the y and z axis of a object? 1 Answer

How am I able to move my (Player) character in the opposite direction of where I am shooting? 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