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 /
avatar image
0
Question by StevenUnu · Jun 08, 2018 at 05:37 PM · spells

Ideas on how to check if mouse moved in a specific shape

I am making a game where the player has to do some "spells". These spells are made by drawing shapes with the mouse. I have an object that is put on a canvas and moves with the mouse clicking, holding and dragging. It has a trail renderer. The problem is that I don't really know how to know if the player did any spell correctly. Spells are symbols that the player has to draw. For example, drawing the ">" sign top to bottom, triggers an attack spell. I tought that I could detect the angle given by

 float alpha =  Vector2.Angle(lastPoint - currentPoint, Vector2.right)
 // lastPoint is the point from where the mouse started
 // currentPoint is the point where the mouse is now

then check:

 Mathf.abs(alpha - lastAlpha) > 10
 // lastAlpha is 0 at the beggining then when this becomes true:
 lastAlpha = alpha

to detect when the direction was changed. Then, according on some length and x/y distance criteria I could detect if any of the spells was made. But this doesn't really work. I tought that I could save spells as an object:

 class Spell {
    public string name;
    Vector2[] directions;
 }

So for example ">" is { name: "attack", directions: [ new Vector2(40, 20), new Vector2(-40, 20) ] }, meaning that you have to go at least 40 to the right and 20 down, approximately half of x on y and then at least 40 left and 20 down, approximatley half of x on y.

I know this seems hard but maybe there is an easy solution. I would like any help even if it means rethinking the whole system. Thank you.

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 b1gry4n · Jun 08, 2018 at 10:08 PM

just spitballin here... if you were to put an "invisible" grid in front of the camera and had the mouse activate/deactivate certain grid squares you could then create spell templates that you could compare against.

alt text

so in this example the user missed 2 grid squares of the spell and made 3 errors. you could do a check to allow some error wiggle room. if(missedCount) < 3 && userErrorCount < 3) or even compare against your "spell book" to find the spell that closest fits the user input shape. i accidentally drew the user input/compare charts off by a grid space, but i think the idea comes across still


1.jpg (83.8 kB)
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

82 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

Related Questions

Breaking from a Loop 2 Answers

How to create effects that encase objects? 0 Answers

StatusEffect System - While Loop Being Skipped Over and Cancelled 0 Answers

Cooldown Spells and Icons 0 Answers

Best approach for spell book and spell bar (using composition) 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