Jump to content
  • Advertisement
Sign in to follow this  
LauraJo

I need coding help please!

This topic is 520 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everyone!

          Im fairly new to creating my own games. Im using unity and monodevelop to create my games. Im taking a course on udemy and the course is learning to code. Ive put several posts on there but no one seems to answer to their forums so im trying this route and I hope, that someone can help me.

 

so this is my issue.

 

Im creating a space laser shooter game. (its part of my project). They have videos that help and guide you step by step which is a great way, UNTIL you do everything correctly and I mean everything because i checked it 128473248756 times, and something ends up not working right. I have an enemy formation that is supposed to move left to right or right to left bouncing off the play space. My enemies keep getting stuck on the left side of my play space. They did a specific video about to fix this error but its not working for me, my enemies still keep getting stuck. Down below ive provided my code. Feel free to email me at cabanlaura@gmail.com if you are able to help me :) i would greatly appreciate it. I really hate getting stuck :( 

 

Share this post


Link to post
Share on other sites
Advertisement

It looks to me like your min and max are not initialized (and thus default to zero)? The seeming consequent of this is that your rightEdgeOfFormation > max is always true, which means that movingRight is false, which means that movingLeft is always true, and that you will thus always be seeming to move left. 

Edited by AfroFire

Share this post


Link to post
Share on other sites

xmin and xmax are set in lines 22/23, based on the boundaries established on lines 20/21.

 

That's why I asked if in lines 20/21 they intended for right and left boundaries (used to set xmin and xmax) were supposed to both be identical.  I'm pretty sure they were meant to be different.

Share this post


Link to post
Share on other sites

I think frob was correct. Your rightBoundary should probably be declared as in this example:
https://docs.unity3d.com/ScriptReference/Camera.ViewportToWorldPoint.html

 

Something like 

Vector3 rightBoundary = Camera.main.ViewportToWorldPoint(new Vector3(1, 1, distanceToCamera));

 

I think using (0, 0, distanceToCamera) gives you the bottom-left point and using (1, 1, distanceToCamera) gives you the top-right point. The x coords of those should be the xmin and xmax, respectively. 

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!