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 1instrument · Nov 11, 2015 at 03:29 AM · addforceanglecontrolsfiring

Bowman 2 style archer control AddForce?

Hello all.alt text

I am trying to figure out how to script the mechanic (C#) from "Bowman 2" (web game), where your angle of leftMouseDown to leftMouseUp == player's firing arc, and the distance between leftMouseDown and leftMouseUp is the amount of force (AddForce?) applied to arrow. I'm sure it's not that hard, but I am very new to programming.

I was playing around with a Spring Joint2d, but I can't figure out how, and when to instantiate Arrow upon leftMouseDown vs leftMouseClickUp. Like, if I instantiate Arrow upon release (after the drag of the mouse), then how could the spring be stretched during the drag, and then be applied to the Arrow, if at that point the Arrow hadn't been created yet? Also, in a game with multiple Arrows shot by a moving character, it doesn't seem like I would want SpringJoints?!?

Maybe SpringJoint2D is a bad idea, but I'm trying...

Even just an explanation of an approach would be helpful. i.e. Thank you very much for your time!

bowman-example.jpeg (3.6 kB)
Comment
Add comment · Show 3
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 ZefanS · Nov 13, 2015 at 09:02 AM 1
Share

This is the general approach I would take:

  • On a mouse click and hold, record the initial cursor position and then continually check the cursor position (and do any visual feedback stuff)

  • When the mouse is released, calculate the vector between the cursor position at release and the original click location (myVector = cursorInitialPosition - cursorPosition) and calculate the length of the vector (Vector2.length(myVector) I think).

  • myVector represents the direction the arrow will be shot, and it's length (multiplied by some constant) represents the strength of the shot.

  • Instantiate the arrow and use Rigidbody.AddForce with myVector as the direction and it's length as the force.

Hope this helps.

avatar image 1instrument ZefanS · Nov 14, 2015 at 12:47 AM 0
Share

Thank you ZefanS! That was a very clear and helpful explanation. I have since figured out a way or two to shoot the arrow, now I'm struggling to rotate the thing properly. I have asked another question about it, can't find the link, but you have helped enough already. I appreciate you!

avatar image ZefanS · Nov 16, 2015 at 12:31 AM 1
Share

Glad I could help.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by bowman123 · Sep 13, 2016 at 05:30 PM

@1instrument There is one more game similar to the one you linked called Apple Shooter. Also man i am struggling to find your thread on arrow rotation. Did you find an answer and can you link the thread from here? thanks!

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 1instrument · Sep 13, 2016 at 06:49 PM

Never did figure out how to rotate it... ☹️

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

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

36 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

Related Questions

Add force with acceleration 2 Answers

[Unity2D] Firing bullets based on gun orientation 1 Answer

Pc controls to mobile controls 0 Answers

Angles and Linecasting 2 Answers

Raycast under crosshair 0 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