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 Deadman9527 · Aug 05, 2014 at 07:16 AM · gameobjecttransformtrigger

A transform.position to act as a Vector3

I have been looking high and low of how to have my fireball that hits the enemy, it will transform on the GameObject. I succeeded, the only problem is that when the enemy moves, the fireball or I mean to be specific, the particle does not follow along with the enemy it instead just spawns in the previous location that the enemy was last at when it made contact. Which in fact just typing out how my script works gives me an idea of how to fix the issue, but need more help.

I was thinking that since I have Random.Range and rigidbody.addforce, somehow could I stop it by someway because every time the object is instantiated and it hits the enemy it continues to push on forward, but in some cases when I used Rigidbody.velocity it would do what I was saying in the previous paragraph.

My Main goal that I may think solve the problem unless you have a better idea :D. Is there a possible way of having a transform.position act as a vector3 as well as transform.rotation act as one as well.

But anyway my script:

 #pragma strict
 
 var FireBallSpawn : GameObject;
 var FireBall : Transform;
 var Enemy : GameObject;
 var EnemyPosition : Transform;
 var Character : Transform;
 var Speed = 100;
 var DestroyTime = 10;
 var DelayTime : float = 0.5f;
 var NextFireBall : float = 0.0f; 
 
 function Update () 
 {
     if(Input.GetButtonDown("Fire1")&& Time.time > NextFireBall)
     {
         NextFireBall = Time.time + DelayTime;
         var FireBallDirection :  Vector3 = Character.TransformDirection(0, 0, 10);
         var clone = Instantiate(FireBallSpawn, Character.position, Character.rotation);
         clone.rigidbody.AddForce(FireBallDirection*Speed);
         Destroy(clone, DestroyTime);
     }
 }
 
 function OnTriggerEnter (info : Collider) 
 {
     if(info.tag == "Enemy")
     {
         var rotationspeed : float = Speed*Time.deltaTime;
         FireBall.transform.parent = Enemy.transform;
         FireBall.rigidbody.velocity = EnemyPosition.position;
     }
 }

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

Answer by Dzoni94 · Aug 05, 2014 at 08:32 AM

Rigidbodies get affected by physics regardless of their parent, meaning that even if your fireball is parented to the enemy, it will still be affected by gravity and will fall down etc. Solution is to destroy the rigidbody component on hitting the enemy. You can do this by simply adding Destroy(FireBall.rigidbody); inside the OnTriggerEnter function after checking if the trigger was the enemy.

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 Deadman9527 · Aug 05, 2014 at 02:33 PM 0
Share

Thank you so much, like this problem has been bugging me for 2 days now. Here it is if anyone is curious to what I did with his statement:

 function OnTriggerEnter (info : Collider) 
 {
     if(info.tag == "Enemy")
     {
         Destroy(FireBall.rigidbody);
         FireBall.transform.parent = Enemy.transform;
     }
 }

Also I later discovered in the context of what I was trying to put down in regards of the Transform.position and Transform.rotation already acts like a Vector 3 and Quaternion.Identity anyway. $$anonymous$$y problem here was, that force was still being applied to the particle effect, while parenting with the GameObject at the same time. So getting rid of the rigid body itself will stop the force of the particle and rather act as a normal transform when parenting with an object. :D

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

My script doesnt respond what i wrote HELP!!! 0 Answers

Check if trigger collider is touching other trigger collider 2 Answers

trying to make an object move up and stop via trigger 1 Answer

Acces to other object trigger thru other object script 0 Answers

C# Function Transform to Gameobject Convert 1 Answer


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