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 AC_Sandy_SK · Dec 12, 2021 at 09:21 AM · velocityprefab-instancetransform.translate

Unity2D Parent of prefab is instantiating, but not moving.

Hi. I want to make some spikes as obstacles in my game. I wanted to give feedback based on where the bullet hits the spike. Since spike has a slanted surface, i couldnt use box colliders to check for triggers. So I split the spike into 4 objects, from top to bottom and added box colliders to each object. And then added them into a parent object called Spike. I made prefabs for all the 4 spike objects and the parent Spike object too. My problem is, I can instantiate the Parent Spike, but I couldnt move it. I added a rigidbody2D to it and still cant move it. In the Inspector window, the transform position value is changing, but nothing is changing in the scene/game views.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class SpikeManager : MonoBehaviour
 {
     public Transform spikeTopPoint;
     public Transform spikeBottomPoint;
     public GameObject spikePrefab;
 
     private bool canMakeSpike = false;
     public float spikeDelay = 1f;
     public float spikeSpeed = 30f;
 
     void Start()
     {
         canMakeSpike = true;
     }
 
     void Update()
     {
         if (canMakeSpike)
         {
             StartCoroutine(Spike());
         }
     }
 
     public IEnumerator Spike()
     {
         //Instantiate your projectile
         MakeSpike();
         canMakeSpike = false;
         //wait for some time
         yield return new WaitForSeconds(spikeDelay);
         canMakeSpike = true;
     }
     
     void MakeSpike()
     {
         //Transform spikePoint = spikeBottomPoint.transform;
         
         GameObject spikeInstance = Instantiate(spikePrefab, spikeBottomPoint.position, spikeBottomPoint.rotation);
         //spikeInstance.GetComponent<Rigidbody2D>().AddForce(-transform.right * spikeSpeed, ForceMode2D.Impulse);
         //spikeInstance.GetComponent<Rigidbody2D>().velocity = Vector2.left * spikeSpeed * Time.deltaTime;
         //spikeInstance.transform.Translate(-transform.right * spikeSpeed * Time.deltaTime);
         //spikeInstance.transform.position -= transform.right * spikeSpeed * Time.deltaTime;
     }
 }


This is the code I'm using to instantiate the spike and to move it. As you can see, I tried different ways. The individual child spike parts are working fine. They give collider feedback and even move if i substitute them instead of the parent Spike.

If this is not solved, instead of box collider, I might try an edge collider and edit the edge to the slanted spike shape. But I wonder if I can check for the bounds of it.

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

0 Replies

· Add your reply
  • Sort: 

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

132 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

Related Questions

Velocity powered rigidbody on a moving platform without parenting. 3 Answers

How do I make a velocity counter without rigidbody.velocity.magnitude? 0 Answers

Error: Method not found: 'UnityEngine.Rigidbody.Translate'. 1 Answer

Help fixing AI? 1 Answer

Disable/Enable game object by clicking instantiated prefab during runtime 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