Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Marsallima · Dec 29, 2011 at 11:15 PM · transformpositionvector3fpsgun

Aim Down Sights Positioning Problem

guys, i have a problem, how i make to this script "CHANGE" the x,y,z without "ADDING" the coordinate numbers

example, i put on script to change the xys of a object

y: 0.111 x: 0.111 z: 0.111

and on the object have this xys

y: 0.300 x: 0.300 z: 0.300

the script now make this

y: 0.400 x: 0.400 z: 0.400

i want the object move to xys give by script not add coordinate

( y: 0.111... )

Here is the code:

 var applymode : boolean;

 

 var smoothTime : float;

 private var velocity = Vector3.zero;

 

 var PositionX : float;

 var PositionY : float;

 var PositionZ : float;

 

function Update () {

 if(Input.GetButton("Fire2") && !applymode){

 

     //Ajusta as cordenadas para virar "Vector3"

     var targetPosition : Vector3 = transform.TransformPoint(Vector3(PositionX,PositionY, PositionZ));

     

     //Pega as cordenadas e faz a mudança de posição :D

     transform.position = Vector3.SmoothDamp(transform.position, targetPosition,velocity, smoothTime);

     

 }



 if(applymode){

 

     //Ajusta as cordenadas para virar "Vector3"

     var targetPositionH : Vector3 = transform.TransformPoint(Vector3(PositionX,PositionY, PositionZ));

     

     //Pega as cordenadas e faz a mudança de posição :D

     transform.position = Vector3.SmoothDamp(transform.position, targetPositionH,velocity, smoothTime);        

 

 }    



}

Comment
Add comment
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
3
Best Answer

Answer by Rod-Green · Dec 29, 2011 at 11:36 PM

Try this:

 var applymode : boolean;
 
 
 
 var smoothTime : float = 1.0f;
 
 private var velocity = Vector3.zero;
 
 
 
 var PositionX : float;
 
 var PositionY : float;
 
 var PositionZ : float;
 
 
 function Apply()
 {
     //Ajusta as cordenadas para virar "Vector3"
 
     var targetPosition : Vector3 = Vector3.Lerp(transform.position, Vector3(PositionX,PositionY, PositionZ), Time.deltaTime * smoothTime);
 
 
     //Pega as cordenadas e faz a mudança de posição :D
 
     transform.position = targetPosition;
 }
 function Update () {
 
     if(Input.GetButton("Fire2") && !applymode){
         Apply();
     }
     
     
     
     if(applymode){
     
         Apply();
     }    
 }
Comment
Add comment · 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 Marsallima · Dec 30, 2011 at 12:47 AM 0
Share

Thanks Rod, bur continue the problem :/ OBS: The code It is within object that is to be moved... The object not stay on the cordenates give by me :/

avatar image Rod-Green · Dec 30, 2011 at 12:54 AM 0
Share

You're english isn't too clear. Can you please explain the issue more clearly?

avatar image Marsallima · Dec 30, 2011 at 01:38 AM 0
Share

i'm trying to make the script move the object with the local coordinates, the script that you have gave to me, he "adds" one coordenate to another

avatar image Rod-Green · Dec 30, 2011 at 01:55 AM 1
Share

Technically the script I gave you 'overrides' the position to the values given - it doesn't add at all but rather sets it absolutely to the fixed world coordinates.. if you want it to set local you can do something like:

   function Apply()
   {
       //Ajusta as cordenadas para virar "Vector3"

       var targetPosition : Vector3 = Vector3.Lerp(transform.localPosition, Vector3(PositionX,PositionY, PositionZ), Time.deltaTime * smoothTime);


       //Pega as cordenadas e faz a mudança de posição :D

       transform.localPosition = targetPosition;
   }
avatar image Marsallima · Dec 30, 2011 at 02:14 AM 0
Share

Well, I tested for example, put the same coordinates of the object in the script and stay on same location: D but if I change it will not properly :/

But what I'm trying to do, I move the first gun (For the position of target), I copy the coordinates and put in the script, then put the gun in the usual plac., What happens when I run "apply", the weapon is not in the right place. :/

Show more comments

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

I need help with the location of instatiated objects on the scene and correct interaction with this 2 Answers

Avart Fate with Gun Movement 0 Answers

How to get a point along an object x distance away from its pivot 1 Answer

transform.position as variable to lock object 0 Answers

How to stop transform movement at a certain point? 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