Advertisement

I need coding help please!

Started by February 12, 2017 04:14 AM
3 comments, last by tomd1013 7 years, 10 months ago

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 :(

Look at lines 20 and 21. Did you intend your right and left boundaries to be identical?

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.

AfroFire | Brin"The only thing that interferes with my learning is my education."-Albert Einstein

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.

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.

This topic is closed to new replies.

Advertisement