Game Development Reference
In-Depth Information
void BasicMovement()
{
transform.Translate(Vector3.forward *
(Time.deltaTime * Speed));
}
void DropMovement()
{
transform.Translate(new Vector3(0, DropSpeed,
1) * (Time.deltaTime * Speed));
}
void Update()
{
switch(moveType)
{
case MovementType.Basic:
BasicMovement();
break;
case MovementType.Drop:
DropMovement();
break;
}
}
In the Update function, we check the moveType variable in a switch statement to
determine how the projectile will move through the air. Depending on the value you
assign to it, it'll either call the BasicMovement function or the DropMovement func-
tion. Let's take a look at the BasicMovement code:
transform.Translate(Vector3.forward *
(Time.deltaTime * Speed));
Here we set the transform of the GameObject to move forward in the z axis. We
multiply the movement Vector by deltaTime and our Speed variable. The Speed
variable will allow you to control how fast or slow the projectile will go:
Search WWH ::




Custom Search