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 bitsacpce · May 30, 2018 at 04:25 AM · spawningcharacter movementdirectionstaptomove

3d Model Movement according to platform spawning

I am new to unity and started creating a simple zigzag game. The platforms initially spawn in the X and Z directions and the player changes direction on screen tap in X and Z directions.

After, lets say, spawning of 30 platforms, i switch the platform spawning to -X and Z axis. How do I inform my 3d model that now on screen tap, it has to change directions in -X and Z axis.

I have written the code but the problem occurs that I am not able to tell my character when the direction switch occurs. So it happens that the platforms are still spawning in X and Z axis, but my character now moves in -X and Z axis.

How do i bring platform spawning and character directions in sync?

Comment
Add comment · Show 2
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 SohailBukhari · May 30, 2018 at 04:30 AM 0
Share

Share your code, where you are spawning, and elaborate what is platform?

avatar image bitsacpce SohailBukhari · May 30, 2018 at 04:54 AM 0
Share

@SohailBukhari

Here is the code for platform spawning

void SpawnPlatform() {

 if(score  < 30)
 {
     int rand = Random.Range(0, 6);
     if (rand < 3)
     {
         SpawnX();
     }
     else if(rand >= 3)
     {
         SpawnZ();
     }
 }
 if(score > 30)
 {
     int rand = Random.Range(0, 6);
     if (rand < 3)
     {
         SpawnNegX();
     }
     else if(rand >= 3)
     {
         SpawnZ();
     }
 }

 void SpawnX()
 {
     Vector3 pos = lastPos;
     pos.x += size;
     lastPos = pos;
     Instantiate(platform, pos, Quaternion.identity);

     int rand = Random.Range(0, 4);
     if (rand < 1)
     {
         Instantiate(diamonds, new Vector3(pos.x,pos.y+1,pos.z), diamonds.transform.rotation);
     }
     
 }

 void SpawnNegX()
     {
     Vector3 pos = lastPos;
     pos.x -= size;
     lastPos = pos;
     Instantiate(platform, pos, Quaternion.identity);

     int rand = Random.Range(0, 4);
     if (rand < 1)
     {
         Instantiate(diamonds, new Vector3(pos.x,pos.y+1,pos.z), diamonds.transform.rotation);
     }
     
     }

 void SpawnZ()
 {
     Vector3 pos = lastPos;
     pos.z += size;
     lastPos = pos;
     Instantiate(platform, pos, Quaternion.identity);

     int rand = Random.Range(0, 4);
     if (rand < 1)
     {
         Instantiate(diamonds, new Vector3(pos.x, pos.y + 1, pos.z), diamonds.transform.rotation);
     }
 }


and this for the character controller. The issue is here. how do i inform the character that now switch directions between -X and Z ins$$anonymous$$d of X and Z.

 void Update () {
     if (!started)
     {
         if (Input.Get$$anonymous$$ouseButtonDown(0))
         {
             rb.velocity = new Vector3(speed, 0, 0);
         }
     }

     if (!Physics.Raycast(transform.position, Vector3.down, 1f))
     {
         rb.velocity = new Vector3(0, -25f, 0);
     }

     if (Input.Get$$anonymous$$ouseButtonDown(0) && !gameOver)
     {
         SwitchDirection();
     }
 }

 void SwitchDirection()
 {
     if (rb.velocity.z > 0)
     {
         rb.velocity = new Vector3(speed, 0, 0);
     }else if(rb.velocity.x > 0)
     {
         rb.velocity = new Vector3(0, 0, speed);
     }
 }


I am replicating the classic zigzag game but spawning platforms in the other directions as well. so it looks like the original game for now.

alt text

images.jpg (5.8 kB)

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

85 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

Related Questions

problem with set tag in unity network 0 Answers

SteamVR - Spawning Prefab on Controller,SteamVR - Spawning Objects on Controller 0 Answers

How to randomly spawn objects above the ground? 1 Answer

How to respawn items along with player 1 Answer

Spawn and Destroy problem snake like 2 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