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 Trild123787898 · Mar 18, 2019 at 11:14 AM · scripting problemtransformscript.jointsmovetowards

does not want to work MoveTowards

Why does MoveTowards not want to work? Of course, if you turn on isKinematic then everything works, but this is not a way because the joints do not work well! script: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems;

 public class ConnectObjectPlayer: MonoBehaviour
 {
     public Transform target;
     public GameObject gmo;
     public float speed;
     private bool invite = false;
     public HingeJoint BlazeIt;
     public Rigidbody targetJoint;
     void Start()
     {
       //  BlazeIt = gameObject.GetComponent<HingeJoint>();
     }
     void OnTriggerEnter(Collider other)
     {
 
 
         if (other.CompareTag("Player"))
         {
             invite = true;
         }
     }
 
     void OnTriggerStay(Collider other)
     {
         if (Input.GetKey(KeyCode.E))
         {
             invite = true;
             transform.SetParent(other.transform, true);
             gmo.transform.localRotation = Quaternion.identity;
            // BlazeIt = gameObject.GetComponent<HingeJoint>();
            // BlazeIt.connectedBody = targetJoint;
         }
     }
     void OnTriggerExit(Collider other)
     {
         invite = false;
     }
     void Update()
     {
 
         float step = speed * Time.deltaTime;
         if (invite)
         {
             if (Input.GetKeyDown(KeyCode.E))
             {
                 transform.position = Vector3.MoveTowards(transform.position, target.position, step);
                // BlazeIt = gameObject.GetComponent<HingeJoint>();
 
                
                 //BlazeIt.connectedBody = targetJoint;
 
             }
         }
         
 
     }
 
 
   /*  void FixedUpdate()
     {
 
 
         if (Input.GetKeyDown(KeyCode.R))
         {
 
 
             transform.SetParent(null);
         }
     }*/
 }
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
0

Answer by WarmedxMints · Mar 18, 2019 at 11:23 AM

GetKeyDown only returns true in the frame that the key is pressed in. Therefore your code to move towards it only being executed for one frame each time the E key is first pressed. That is not the only thing wrong with your code by the sounds of it. It may be worth asking a question relating to what it is you are trying to do.

Comment
Add comment · Show 5 · 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 Trild123787898 · Mar 18, 2019 at 12:35 PM 0
Share

I need so that when I press a key, I approach the transport! and control with joints! Should I do a sharing with the help of a joint? just how to do it! and everything should be in OnTrigger

avatar image Ampharel Trild123787898 · Mar 18, 2019 at 12:47 PM 0
Share

What you do can work, but you'll need to change:

 if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.E))

to

 if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.E))

Input.Get$$anonymous$$eyDown, as @Warmedx$$anonymous$$ints stated, is only ran the first frame the button is pressed. Input.Get$$anonymous$$ey will be ran every frame as long as the button is held.

avatar image Trild123787898 Ampharel · Mar 18, 2019 at 01:38 PM 0
Share

nothing has changed! It seems that when I arrive at this moment. it doesn't want to work

avatar image WarmedxMints Trild123787898 · Mar 18, 2019 at 01:46 PM 0
Share

I am sorry but none of what you said has made any sense to me. What is it you are trying to do?

avatar image Trild123787898 WarmedxMints · Mar 18, 2019 at 02:02 PM 0
Share

I have transport and equipment for him, there are joints on them, I need that when the transport runs to the equipment, when I press a key, it comes close to him and I can control it, but the problem is most likely that when I turn off the ConnectedBody using the script Owned after this, it does not want to put in its place!

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

202 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 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 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

How to manage an object using joints? 0 Answers

LocalRotation does not work 1 Answer

The position of the object and its changes! Help me can not understand! 0 Answers

How to fix the problem with joint! HELP I CAN NOT UNDERSTAND! 0 Answers

Help with tractor technology 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