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 Party Boy · Mar 26, 2014 at 03:27 PM · c#movementrigidbodyinstantiatetransform

Instantiated projectile always floats up

I have a Light_Spell script attached to a magic wand which is parented to a Razer Hydra hand object. The Light_Spell takes a prefab of a Light which is projected out of it when a button is pressed. However the light is just moving up, no matter what way I rotate the hand object, it always goes up. I had it working but I changed some code around and can't remember how I got it working in the first place.

Here is the code I have so far:

     if (isSelectedSpell && SixenseInput.Controllers[0].GetButtonDown (SixenseButtons.BUMPER) && triggerIsPressed == false) {
         Rigidbody instantiateProjectile = Instantiate(wandLightProjectilePrefab, transform.position, transform.parent.transform.rotation) as Rigidbody;
     }

I have tried setting Vector3 to up and forward and a whole set of different things. Any ideas on what I should do to make it match the rotation of where the hand is pointing and stuff? Thanks

Comment
Add comment · Show 8
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 Ed unity · Mar 26, 2014 at 03:37 PM 0
Share

If this is true (Wand with Light_Spell Script is child of Razer Hydra hand), then my assumption is that the wand's rotation is either 180 degrees on the x or z axis. that would put the Vector3.down pointing towards the world.up. Try using transform.parent.transform.rotation and see what happens.

avatar image Leuthil · Mar 26, 2014 at 03:38 PM 0
Share

So no matter what direction you choose it always goes up where? In World coordinates or relative to the back of the hand? Have you tried using .localPosition?

It could be a rotation thing as Ed mentioned. But if you tried every direction then it may be something else. It's definitely strange behaviour.

avatar image Party Boy · Mar 26, 2014 at 08:00 PM 0
Share

@Edunity Yeah I tried that just there and nothing happened :S I got rid of the line:

instantiateProjectile.position += Vector3.down * 20.0F;

and the light still just moves up when I used this as the instantiate:

Rigidbody instantiateProjectile = Instantiate(wandLightProjectilePrefab, transform.position, transform.parent.transform.rotation) as Rigidbody;

avatar image Leuthil · Mar 26, 2014 at 08:03 PM 0
Share

What exactly is this wandLightProjectilePrefab that you are spawning? Is it some sort of particle system or just a Point Light?

avatar image Party Boy · Mar 26, 2014 at 08:03 PM 0
Share

@Leuthil I have tried forward and down and get the same thing. When I add in that line I keep getting nullreferenceexceptions on the line after I make the rigidbody. I have dragged the prefab onto the script in the inspector so not sure why it is saying it isn't set to the instance of an object

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by trololo · Mar 26, 2014 at 09:46 PM

 RaycastHit hit;
 
 if(Input.GetMouseButtonDown(0) && Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
 {
    GameObject projectile = Instantiate(projectilePrefab);
    StartCoroutine(MoveTo(projectile, hit.point);
 }
 
 // ...
 
 IEnumerator MoveTo(GameObject proj, Vector3 hit)
 {
     while(Vector3.Distance(proj.transform.position, hit) > 1)
     {
         proj.transform.position = Vector3.Lerp(proj.transform.position, hit, Time.deltaTime);
         yield return null;
     }
 }
    
Comment
Add comment · Show 5 · 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 Party Boy · Mar 26, 2014 at 10:53 PM 0
Share

@trololo this didn't work. the light started far away from me and like moved towards me and then curved up and went out of the scene. closer than where I was before however

avatar image trololo · Mar 27, 2014 at 08:36 AM 0
Share

Well just instantiate your projectile at your player location!

  GameObject projectile = Instantiate(projectilePrefab, transform.position, transform.rotation);
avatar image Party Boy · Mar 27, 2014 at 10:57 AM 0
Share

@trololo It didn't work but I managed to fix the problem

avatar image trololo · Mar 27, 2014 at 12:40 PM 0
Share

You're so badass

avatar image Party Boy · Mar 27, 2014 at 01:11 PM 0
Share

Yeah eat pussy all day erryday

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

22 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

Related Questions

Making a bubble level (not a game but work tool) 1 Answer

Projectile not moving properly in top down 2d shooter 2 Answers

How to allow movement of game object to certain points only 1 Answer

Moving a Rigidbody Relative to Camera Direction 0 Answers

Problem with iTween and instantiated path 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