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 Vandarthul · Apr 23, 2014 at 02:53 PM · c#javascriptmagicspell

A question about making spells(magic)

Hello there, I am trying to create a spell for my game that will basically do this: while the player is moving, the spell leave a trail of something that will give damage to enemies while they are standing on it (something like this: Shyvana Ulti)

So I am currently doing this: When the spell is activated, I take my player's position in a variable and controlling the distance between that position and player's current position. So basically, I instantiate a prefab(that is my spell) to world for every x unit my player moves on

As code:

 void Update () 
 {
     if (Vector3.Distance(sneakAttackDropPos, transform.position) > sneakAttackDropDistanceConst) 
     {
     sneakAttackDropPos = transform.position;
     Instantiate(sneakAttackFX, transform.position, transform.rotation);            
     }
 }

When I press [space] my sneakAttackDropPos is filled with my transform.position. sneakAttackDropDistanceConst this variable is the value of on every x units of my player moves, the spell should be instantiated, so its 1.5f and on every 1.5f unit of my player movement it instantiates my spell.

This works quite fine and as expected but here is the problem: I don't want my player to instantiate my spell on the ground where there is already a spell on it. Basically I don't want sneakAttackFX to be instantiated on same locations.

What have I tried to fix the problem: Controlled OnTriggerStay and OnTriggerExit in a script that has been attached to my sneakAttackFX object. So if my character is OnTriggerStay of my sneakAttackFX object, I false'd a variable and if that variable is false, my Instantiate will not work on player object, this has led to unexpected thus no good solution.

I have nothing else in my mind to fix this problem, so I am asking you this:

  1. If this is a good way of doing something like this

  2. If there is any, what are better options that can yield better results?

Thanks in advance.

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
2
Best Answer

Answer by Vonni · Apr 23, 2014 at 04:36 PM

I think you are on the right track, but I would not use any onTrigger or collision checks.

What I would do:

  • Activate spell.

  • Now check distance to spell

  • If distance is > constant, drop new spell

  • Now check for all spells

Basicly check distance to all spells positions stored in an array of some kind. Let me know if you dont know how that works.

GL

Comment
Add comment · Show 4 · 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 Vandarthul · Apr 23, 2014 at 06:38 PM 0
Share

I though of trying something similiar to what you've said after I wrote here, So before I drop the spell, I will check if there are any spell near the player with OverlapCircleAllNonAlloc and drop the spell accordingly. Would that be fine solution on your opinion?

avatar image Vonni · Apr 23, 2014 at 06:51 PM 0
Share

Sure, if are going to have a collider on the "spell/effect" anyway, then go for it. But probably faster to check distance.

avatar image Vandarthul · Apr 23, 2014 at 08:47 PM 0
Share

What you actually offer is to control every single spell's distance to player's distance and if even one of them is smaller then my constant don't drop the spell, right?

avatar image Vonni · Apr 24, 2014 at 07:13 AM 0
Share

yeah <-<-<-<-<-<

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

21 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

Related Questions

Multiple Cars not working 1 Answer

Trouble Adjusting Stats (MP After Casting A Spell) 2 Answers

Distribute terrain in zones 3 Answers

Can I use Javascript (Unityscript) for Box2D for Unity or Farseer Physics? 1 Answer

C# Gravity Gun. Error CS0120 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