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 NickK10 · Jan 27, 2015 at 03:47 PM · physicstransformdirection

Continue object in the current direction of travel

alt text

Hello, this is all centered in 2D. So even know I am utilizing Vector3s, It's all Vector2 Space.

Currently, I have it on my mobile device where when I touch, a cube is lerped to the touch position. But then it stops. I'd like to have the cube, once within 1 meter (already setup) from the touch position to then continue, and not stop, on it's 2D course.

I've tried a lot of things, and a lot of questions, and a lot of answers. But none seem to satisfy a 2D scenario? Thanks in advanced.

Comment
Add comment · Show 1
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 NickK10 · Jan 28, 2015 at 06:32 AM 0
Share
             Vector3 dir = touchPosition - transform.position;
             rigidbody2D.AddForce(dir * 5);

This just makes the cube 100% erratic, going in random directions. :l

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by DanSuperGP · Jan 28, 2015 at 12:29 AM

Use physics...

Add a rigidbody to the cube

Rather than moving the transform with a lerp, add force in the direction you want it to travel.

Comment
Add comment · Show 6 · 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 NickK10 · Jan 28, 2015 at 12:31 AM 0
Share

Here, you're going to simple. I've been working with Unity for years I would have tried that first.

The problem is, I can't think of a calculation that could provide me with the 2D current direction of travel in a local sense. I can't launch it forward without knowing the direction to launch it in? How can I find the current direction of travel, to then use it how you said.

avatar image DanSuperGP · Jan 28, 2015 at 12:36 AM 0
Share

uh... you already calculated the vector in your code...

touchposition - transform.position...

just normalize it... multiply it by the force you want to add...

avatar image NickK10 · Jan 28, 2015 at 12:47 AM 0
Share

That's what I thought but it just glides in a different position relative to 3D. I don't understand it :l It's been confusing me for so long now. All the logic is correct, but it won't travel.

avatar image NickK10 · Jan 28, 2015 at 12:49 AM 0
Share

This just makes it erratic actually. It goes in different directions depending on where the touch is.

             Vector3 dir = touchPosition - transform.position;
             rigidbody.AddForce(dir * 5);


Edit : on further notice, the cube perfectly orbits the touch position :l

avatar image NickK10 · Jan 28, 2015 at 01:01 AM 1
Share

the vector doesn't change per frame. Nor, well, ever. The code has changed since you last saw

Regardless, any other reason this would be happening?

$$anonymous$$y bad, my IDE didn't update the code :) Looks like changing the vector from an update position did the trick, interesting how I missed that. Thanks though! All fixed!

Show more comments
avatar image
0

Answer by Andres-Fernandez · Jan 27, 2015 at 07:30 AM

Just start a coroutine that moves the cube for the remainder of the distance (the same lerp, but inside a coroutine). Manual reference, API reference.

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 NickK10 · Jan 28, 2015 at 12:14 AM 0
Share

That's not what I was asking. I need to know how to get it to move in its current path once its PASSED the touch :)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Bouncing Ball Problem( bounces vertically forever) 1 Answer

transforming player position on input.get button down 1 Answer

stop vehicle from moving through walls 1 Answer

Player Car Runtime Scaling Issue 0 Answers

Declaring Vector in inspector for directional movement 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