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 /
  • Help Room /
This question was closed Oct 25, 2015 at 08:44 PM by Dicklett.
avatar image
0
Question by Dicklett · Oct 18, 2015 at 08:25 PM · transform.positiondirectionmathfvectorsprojectiles

Changing transform.position through a reference

I have this bone projectile in which I tell which direction to go through this code

     if (Input.GetKey(KeyCode.LeftArrow) && Time.time > (lastFireTime + burstDelay))
     {
         lastFireTime = Time.time;
         GameObject boneInstantiate = Instantiate(shot, shotSpawnLeft.position, shotSpawnLeft.rotation) as GameObject;
         BoneScript bone = boneInstantiate.GetComponent<BoneScript>();
         bone.direction.x = Mathf.Cos(270 * Mathf.Deg2Rad);
         //bone.dir = 1;
         //Debug.Log(bone.direction.x);
     }
     if (Input.GetKey(KeyCode.RightArrow) && Time.time > (lastFireTime + burstDelay))
     {
         lastFireTime = Time.time;
         GameObject boneInstantiate = Instantiate(shot, shotSpawnRight.position, shotSpawnRight.rotation) as GameObject;
         BoneScript bone = boneInstantiate.GetComponent<BoneScript>();
         bone.direction.x = Mathf.Cos(90 * Mathf.Deg2Rad);
         //bone.dir = 2;
         //Debug.Log(bone.direction.x);
     }
     if (Input.GetKey(KeyCode.UpArrow) && Time.time > (lastFireTime + burstDelay))
     {
         lastFireTime = Time.time;
         GameObject boneInstantiate = Instantiate(shot, shotSpawnUp.position, shotSpawnUp.rotation) as GameObject;
         BoneScript bone = boneInstantiate.GetComponent<BoneScript>();
         bone.direction.y = Mathf.Cos(0 * Mathf.Deg2Rad);
         //bone.dir = 3;
         //Debug.Log(bone.direction.y);
     }
     if (Input.GetKey(KeyCode.DownArrow) && Time.time > (lastFireTime + burstDelay))
     {
         lastFireTime = Time.time;
         GameObject boneInstantiate = Instantiate(shot, shotSpawnDown.position, shotSpawnDown.rotation) as GameObject;
         BoneScript bone = boneInstantiate.GetComponent<BoneScript>();
         bone.direction.y = Mathf.Cos(180 * Mathf.Deg2Rad);
         //bone.dir = 4;
         //Debug.Log(bone.direction.y);
     }


and then in another script I make the bone projectile move in that direction through this code

     Vector3 posReference = transform.position;
     Debug.Log(posReference);
     posReference.x = posReference.x + bulletSpeed * direction.x * Time.deltaTime;
     Debug.Log(posReference.x);
     posReference.y = posReference.y + bulletSpeed * direction.y * Time.deltaTime;
     Debug.Log(posReference.y); 
     transform.position = posReference;


The problem is the bone doesn't move at all in that direction and it stays in the position. What am I doing wrong in this code or how should I update transform.position so the bone goes in the direction I want?

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

  • Sort: 
avatar image
0

Answer by Dicklett · Oct 19, 2015 at 12:16 PM

bump i guess?

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

Follow this Question

Answers Answers and Comments

29 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

Related Questions

Predicting the hit point on X axis, based on vector direction 1 Answer

What is the best way to find direction between two objects? 0 Answers

Moving a GameObject in an Ellipsoid path 1 Answer

How can I translate my game object from a certain coordinate to the negative values of the same coordinate? 1 Answer

Clamping a value between two radiuses 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