• 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
Question by MayIAsk · Jan 29, 2017 at 12:54 PM · rigidbody2dvelocitydirectionlookatmoveposition

Issue with direction and rigibody2D

Hello,

I have an issue when I'm trying to send a projectile from a position to an unkown position but driven by a direction. Imagine a bubble game, I want the same behaviour as a bubble you send by clicking on the screen.

So I have a projectile, wall which change direction of this projectile and some block objects where the projectile will collide with and stop moving. This projectile has a Rigidbody2D on and is non-kinematic, that's why I'm using velocity to launch it. The projectile go where I want it to go (toward click direction) but it stops at click position (x and y aixs). I want it to continue until it touches a block object. So the direction is alright (target = click), but I don't know how to tell the projectile to keep going.

There is a piece of code I write to get this result :

 // way = 1 or -1 if the object bounce on a wall it inverse direction in x axis)
 
 //Target = mouse position (direction I want the projectile to follow
 target = new Vector2((way * _mousePosX), _mousePosY);
 
 direction = (target - (Vector2)_itemToThrow.transform.position).normalized;
 
 //I tested with moveposition and lookat same result as velocity 
 //_itemToThrow.GetComponent<Rigidbody2D>().MovePosition((Vector2)_itemToThrow.transform.position + direction* 10 * Time.deltaTime);
 
 /*_itemToThrow.transform.LookAt(target);
 _itemToThrow.GetComponent<Rigidbody2D>().velocity = _itemToThrow.transform.forward * 500;
 _itemToThrow.transform.rotation = new Quaternion(0, 0, 0, 0);*/
 
 
 // This is the actual code, work the same with transform direction or without
 _itemToThrow.GetComponent<Rigidbody2D>().velocity = direction * 100 * Time.deltaTime; // transform.TransformDirection(direction* 50 * Time.deltaTime); 
 

Well if you have any idea how I can send my projectile to a define direction but an "infinite" position at the end it will be appreciated.

Thank you for your help and time !

Comment

People who like this

0 Show 0
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

Answer by MayIAsk · Jan 30, 2017 at 07:40 AM

I don't know if anyone read this but I'm still wondering how to launch an object with no limit. Sorry I don't want to spam or flood.

Thank you

Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How can I get local 2d Velocity? 2 Answers

Rigidbody2D velocity in random direction with exceptions 1 Answer

How do I Control An Objects Movement Only On the X Axis and Have a RigidBody Control Movement on the Y axis? 1 Answer

Set Object Rotation based on Collision (2D) 0 Answers

Move car at same speed 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