Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Pandadankucing · Feb 17, 2018 at 10:57 AM · transform.positiondistanceteleportteleporting

teleport an object three quarters of its distance with the player after a certain time

Hello everyone, I know how calculate a distance beetween the object and the player but i dont know how teleport an object three quarters of its distance with the day after a certain time, then with the half, then with the quarter ... Can you please help?

Thanks in advance.

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 priyank1234 · Feb 17, 2018 at 12:39 PM 0
Share

Very nice post , And also all the topics of this blog are very informational , So i have create an account here for get more information . Thanks for share this information togather . i am very thanks full to you . click here

Thanks .

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by tetramess · Feb 17, 2018 at 12:15 PM

So assume you have X and Y coordinates.
Player has coordinates (pX, pY).
Object has coordinates (oX, oY).
The distance between them is sqrt((pX-oX)^2 + (pY-oY)^2) (sqrt means square root)
To move an object somewhere, you have to calculate what his new position will be. If you want to move him by a quarter, then calculate his new position:
newX = pX +(pX-oX)/4; and newY = oY + (pY-oY)/4; And move the object there (access his transform component and change the x and y values). However be careful - if you use the same formula to calculate how much closer to move the object, then the second time you use it it will move him by a quarter of the new distance, not the old. If you want those increments to stay consistent, you have to make a new variable and assign the increment 'size' by which it will have to change the object's position every time.

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 Pandadankucing · Feb 17, 2018 at 06:53 PM 0
Share

Hi thank you so much for you answer. I have good understant what you have explain me and in theory it look will be good, but i have try and i find one litlle wrong but i dont know where it from : I have transcript and try that you have say me on script and test it :

" public class Test : $$anonymous$$onoBehaviour {

 Transform player;
 public float newX;
 public float newZ;
 [Range(1,100)]
 public float divisor;

 
 void Start () {
     player = GameObject.FindGameObjectWithTag ("Player").transform;
 }

 void Update () {
     if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Alpha3))
     {
         //Calcul de la nouvelle position de l'objet en X : pX = player en X oX := object en X
         //nouveauX = pX + (pX-oX) / 4; et newY = oY + (pY-oY) / 4
         newX = (player.position.x + (player.position.x -transform.position.x)) / divisor;
         newZ = (player.position.z + (player.position.z -transform.position.z)) / divisor;

         transform.position = new Vector3 (newX, transform.position.y, newZ);

         print ( newX);
         print ( newZ);

         divisor--;
     }
 }

} "

And when i test it, the player have deplace but have deplace over player, i dont know well how explain (sorry i'm not english and my english so terrible) , so maybe with litlle draw it will more clear about the problem :

alt text

i dont know what i have wrong or miss understant :(

avatar image
0

Answer by Pandadankucing · Feb 17, 2018 at 09:30 PM

Do you know what is the problem ? :/

Comment
Add comment · 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.

Follow this Question

Answers Answers and Comments

77 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Help Cannot convert type 'PhotonPlayer' to 'UnityEngine.GameObject' 1 Answer

How to teleport the player to the location of an instantiated projectile? 1 Answer

transform.position not a member of system.type 1 Answer

teleport destination differs when player hits trigger from different positions 0 Answers

How to add a teleportation mechanic like ender pearls in Minecraft 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