Making an object move back and forth.

Started by
14 comments, last by Mightymax 7 years, 9 months ago
bool halt;
void init()
{
halt = false; //...
}
void Update ()
{
if (halt) return;
transform.Translate(Vector3.right * movementSpeed * Time.deltaTime);
}

void Execute()

{

Update();

halt = (position_between_two_points(transform.pos, some_point) < 10.0); //that acutally will hold position forever so we go with another update function:

}

void Update ()
{
if (halt)
{
//code here
return;
}
transform.Translate(Vector3.right * movementSpeed * Time.deltaTime);
}
Nopw look how this is stupid: define a throw object, and make it bool fly; yes or no when it flies it travels then it makes sense
Advertisement

(moderator hat on)

A gentle reminder about the special rules of the For Beginners forum.

Specifically:

* This forum is for beginners to ask questions without being harassed because someone more experienced thinks the answer should be obvious.

* Make sure replies are helpful and guiding the beginner in the right direction.

The focus in For Beginners is to help educate, guide, and answer questions in a reasonably safe environment. Even the experts were beginners once. Sometimes the best answers are a code snippet, or a link to a tutorial. Other times the best answers are step-by-step guidance to help think and reason and guide to reach a viable solution.

(moderator hat off)

In a more useful note, it looks like Alberth has been guiding toward the right answer, and those are the correct things to think about to solve this problem and other problems like it.

I'd also break it down similarly:
1. First you need to figure out generally how you are going to move objects. It looks like you've described some shapes.
2. After you know how objects will move, describe those motions as very specific steps. Looks like you've got back-and-forth and square, and possibly circle. Describe those motions in terms of world coordinates and game systems. Describe every step precisely. Eventually you will need to explain it to the computer that will only do exactly what you tell it, nothing more or less. You might try explaining it to an obnoxious person who only does exactly the words you say to make sure you really understand the steps involved.
3. Take the descriptions in regular words, and figure out how to describe it as a series of math steps. For example, a math function where you pass in the current time and the details of the path to follow, then you divide the time by the time it takes to complete a full cycle (at the current time step it is on cycle 2341.36), then compute the portion within the current cycle (it is 36% complete), then compute the position at that time in the cycle (36% of the distance on the path yields coordinates (X,Y,Z) which should be where you set the position). Or another approach might mean a math function where you evaluate the time that has passed (it has moved for 14.6 milliseconds), evaluate the speed and direction it is traveling (7.83 pixels per millisecond in a specific direction), then advance the position based on the time (elapsed time * speed at direction). There are many other ways you might describe the direction.
4. After you've got the steps figured out and you can describe it using math, then attempt to describe it in computer code.

It looks like you're somewhere between step 2 and 3. It can be a struggle, but the skills are vital if you want to develop software. Even in professional work environments we will talk to others to explain every individual step, then explain the steps using the right notations. Sometimes we'll even explain it to an inanimate object to help reason through the steps.

(moderator hat on)

A gentle reminder about the special rules of the For Beginners forum.

Specifically:

* This forum is for beginners to ask questions without being harassed because someone more experienced thinks the answer should be obvious.

* Make sure replies are helpful and guiding the beginner in the right direction.

The focus in For Beginners is to help educate, guide, and answer questions in a reasonably safe environment. Even the experts were beginners once. Sometimes the best answers are a code snippet, or a link to a tutorial. Other times the best answers are step-by-step guidance to help think and reason and guide to reach a viable solution.

(moderator hat off)

In a more useful note, it looks like Alberth has been guiding toward the right answer, and those are the correct things to think about to solve this problem and other problems like it.

I'd also break it down similarly:
1. First you need to figure out generally how you are going to move objects. It looks like you've described some shapes.
2. After you know how objects will move, describe those motions as very specific steps. Looks like you've got back-and-forth and square, and possibly circle. Describe those motions in terms of world coordinates and game systems. Describe every step precisely. Eventually you will need to explain it to the computer that will only do exactly what you tell it, nothing more or less. You might try explaining it to an obnoxious person who only does exactly the words you say to make sure you really understand the steps involved.
3. Take the descriptions in regular words, and figure out how to describe it as a series of math steps. For example, a math function where you pass in the current time and the details of the path to follow, then you divide the time by the time it takes to complete a full cycle (at the current time step it is on cycle 2341.36), then compute the portion within the current cycle (it is 36% complete), then compute the position at that time in the cycle (36% of the distance on the path yields coordinates (X,Y,Z) which should be where you set the position). Or another approach might mean a math function where you evaluate the time that has passed (it has moved for 14.6 milliseconds), evaluate the speed and direction it is traveling (7.83 pixels per millisecond in a specific direction), then advance the position based on the time (elapsed time * speed at direction). There are many other ways you might describe the direction.
4. After you've got the steps figured out and you can describe it using math, then attempt to describe it in computer code.

It looks like you're somewhere between step 2 and 3. It can be a struggle, but the skills are vital if you want to develop software. Even in professional work environments we will talk to others to explain every individual step, then explain the steps using the right notations. Sometimes we'll even explain it to an inanimate object to help reason through the steps.

frob question:

what is the industry term used among software developers on how to break down a game development into steps and objectives like that. I'm looking for some books on the topic. thanks

I would call it "software engineering" :P

Emphasis is on "engineering" though, this analysis process is done in many engineering disciplines, as well as in science. "Software" isn't that relevant here.

From programming point of view, you may want to try "learn programming" books that are not attached to a specific computer language (if they exist, not sure, maybe "software technology" or something?).

From a design point of view, it would classify as detailed design.

frob question:

what is the industry term used among software developers on how to break down a game development into steps and objectives like that. I'm looking for some books on the topic. thanks


There is the term I linked to: rubber duck debugging.

If you can explain all the steps to a rubber duck, step by step, line by line, and make sure the rubber duck understands it, then you can probably find a way to make the computer understand, too.

You've just got to break down the problems into smaller and smaller pieces until they are pieces you can handle. There is a name for that sort of thing, too: divide and conquer. Break the problem down smaller and smaller until you are able to solve every part.

Whatever you end up calling it, that is the set of steps you need to follow. I described two different ways to figure out the motion. Personally I prefer the direct numerical approach of finding the portion of the interval that is complete and then solving for it's position along the path. It is less prone to numeric errors and drift over time, and less subject to skips in time processing delays.

thanks for the replys.

ya looking for "design" - I'm at a point where I understand and have memorized API's and syntax for C languages

but for example is someone asked me:

ex. design and rpg mage to fire a bolt from his staff, I wouldn't know what to do first and how to tackle the issues with the code I know.

This topic is closed to new replies.

Advertisement