• 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 Dartmor · Jun 15, 2015 at 03:23 AM · vector3multiplydivide

Vector3 NextPosition = Position / 1.1; or Vector3 NextPosition = Position * 0.99; ? 1. Position of object is (20,0,20) 2. I need to get (19,0,19)

How to calculate something like

Vector3 NextPosition = Position / 1.1; or Vector3 NextPosition = Position * 0.99; ?

It don't want to work. But i simply need for example: 1. Position of object is (20,0,20) 2. I need to get (19,0,19)

Is there a way to do this somehow?

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

2 Replies

  • Sort: 
avatar image

Answer by Lachee1 · Jun 15, 2015 at 08:09 AM

is it because you forgot to add the F on your floats? so instead of Position / 1.1, it would be Position / 1.1F

Comment
Bunny83
Dartmor

People who like this

2 Show 2 · 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 Bunny83 · Jun 15, 2015 at 08:48 AM 1
Share

I just wanted to post that answer as well but i've found your comment in the last second ^^. I converted it to an answer.

Even though this answer is the correct answer of the original question, it's probably not what the OP actually wants if you read the comments under Addyarb's answer.

Since the distance between two adjacent ringe in that maze is constant it doesn't make sense to use any kind of ratio / percentage as the distance-changed would get smaller when you get closer to the center.

MoveTowards is probably the best solution. However you don't pass Time.deltaTime as step, but the distance between two rings. It should even work with a negative step value to move outwards.

 transform.position = Vector3.MoveTowards(transform.position, Vector3.zero, distance);

This however will of course "jump" to the next ring, so it shouldn't be executed every frame but once when you want to go to the next ring.

avatar image Dartmor · Jun 16, 2015 at 01:46 AM 0
Share

I've tried

  Vector3 Position = transform.position;
                 Vector3 NextPosition = new Vector3(transform.position.x - 1,transform.position.y, transform.position.z - 1);
     
     float step = speed * Time.deltaTime;
                 if (Vector3.MoveTowards (Position, NextPosition, step)) {
                     print ("Move Towards works");
                     GetComponent<ConstantForce> ().force = Vector3.MoveTowards( transform.position*5, transform.position*5, Time.deltaTime*5);
                 }

But IF part doesn't work. Vector3 can't be 'boolean'

So i am trying something like

   newDistance = Vector3.Distance(transform.position, Vector3.zero);
     
     
                 
                 if (newDistance<startDistance) {
                     print ("Move Towards works");
                     GetComponent<ConstantForce> ().force = Vector3.MoveTowards( transform.position*5, transform.position*5, Time.deltaTime*5);
                 }
  startDistance = newDistance;





And it actually works

avatar image

Answer by Addyarb · Jun 15, 2015 at 03:29 AM

 float x = -1; //The x amount to add to the x axis.
 float y = 0; //The y amount to add.
 float z = -1; //The z amount to add.
 //The above values are variable. You can delete these and set them in the inspector.
 
 
 void Start(){
 
 
 
      transform.position = new Vector3(transform.position.x + x,transform.position.y +y, transform.position.z + z);
 
 }
Comment
Dartmor

People who like this

1 Show 8 · 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 Dartmor · Jun 15, 2015 at 06:20 AM 0
Share

Thnx! Ideas about this?

Vector3 Position = transform.position;

             Vector3 NextPosition = new Vector3(transform.position.x - 1,transform.position.y, transform.position.z - 1);
 
 
 
             
             //If object moves to next position, push it away with MoveTowards
             if (Vector3.MoveTowards (Position, NextPosition, Time.deltaTime)) {
                 GetComponent<ConstantForce> ().force = Vector3.MoveTowards( transform.position*2, transform.position*2, Time.deltaTime*2);
             }

or

 Vector3 Position = transform.position;
 
             Vector3 NextPosition = new Vector3(transform.position.x - 1,transform.position.y, transform.position.z - 1);
 
 
 
             
             //If object moves to next position, push it away with MoveTowards
             if (Position = NextPosition) {
                 GetComponent<ConstantForce> ().force = Vector3.MoveTowards( transform.position*2, transform.position*2, Time.deltaTime*2);
             }


avatar image fafase · Jun 15, 2015 at 06:30 AM 1
Share

It is unclear what you want. It seems first you want the object to be placed, for instance from (20,0,20) to (19,0,19) which can be done as such:

   transform.position = new Vector3(19,0,19);

nothing else. If you have a translation, that is some kind of force or movement then you need to know that one vector and apply it:

  transform.Translate(movement);

For instance, you are at (20,0,20) and you wish to move some (1,0,1) then this is the one. If you sue this in the update it will move by that amount each frame, you can use deltaTime but that is out of question scope.

Now if you want o move from a position to another position like from (20,0,20) to (19,0,19), you need to interpolate. This can be done in two ways using Lerp or MoveTowards. It is dependent on how you want the movement to happen.

Lerp takes the distance between current and target then multiplies by the ratio and adds that to hte current position:

   newPosition = Vector3.Lerp(current, target, ratio);

   newPosition = (target - current) * ratio;

This makes movement smaller each run (if target is not moving) and makes it look like it moving and slowing down as it reaches the target. ratio is a value between 0 and 1, 0 being no movement and 1 being full distance.

   newPosition = Vector3.MoveTowards(current, target, step);

Now, regardless of the distance between current and target, the object will move by the amount od step. If step is greater than the distance then target is returned. This create a constant movement, no slow down at the end.

avatar image Dartmor · Jun 15, 2015 at 06:33 AM 0
Share

I simply want IF statement to run each time when object moves from Position(x,y,z) to (x-1,y,z-1)

or not exactly (x-1, y, z-1) , i actually need (x multiply 0.99,y, z multiply 0.99) , but it won't work

avatar image fafase · Jun 15, 2015 at 06:42 AM 1
Share

What would be the situation making the object to move? I mean is it falling with gravity? Do you trigger the movement? What makes it go from A to B?

avatar image fafase · Jun 15, 2015 at 08:06 AM 1
Share

Ok, my advice on this, place a trigger circle (or sphere if 3D) in the middle of the map. And this on it:

 void OnCollisionEnter2D(Collision2D col)
 {
     if(col.gameObject.tag == "Ball"){
          // Call on to start moving, I guess it is meant to be the boats.
     }
 }

Show more comments

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

24 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

Related Questions

Distribute terrain in zones 3 Answers

Vector3 and Quaternion issues. 2 Answers

How to save rotation with PlayerPrefsX? 1 Answer

How do I create a vector that points down from a cube that is rotating on all axis? 5 Answers

Rotate a Vector3 direction 3 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