# How to change Vector3 if an objects rotation is a certain number?

RIght now, I want to check if the rotation of the main object, the conveyor, is 90. If it is 90, change the vector3 called direction to have the values -1, 0, 0. If the rotation is 180, change the direction to 0, 0, 1, along with 0 and 270 degrees. Im getting an error that says “Non-Invocable member ‘Vector3’ cannot be used like a method”. How could I get this to work? So far heres my code:

``````using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ConveyorBelt : MonoBehaviour
{
public Transform ConveyorTransform;
public float speed;
public Vector3 direction;
public List<GameObject> onBelt;

void Update()
{

if(ConveyorTransform.rotation.eulerAngles.y == 0){
direction = Vector3(0, 0, -1);
}
if(ConveyorTransform.rotation.eulerAngles.y == 90){
direction = Vector3(-1, 0, 0);
}
if(ConveyorTransform.rotation.eulerAngles.y == 180){
direction = Vector3(0, 0, 1);
}
if(ConveyorTransform.rotation.eulerAngles.y == 270){
direction = Vector3(1, 0, 0);
}

for(int i = 0; i <= onBelt.Count -1; i++)
{
onBelt_.GetComponent<Rigidbody>().velocity = speed * direction * Time.deltaTime;_
``````

}
}
// When something collides with the belt
private void OnCollisionEnter(Collision collision)
{
}
// When something leaves the belt
private void OnCollisionExit(Collision collision)
{
onBelt.Remove(collision.gameObject);
}
}

There’s a bit more to cover here than just the basic question, so bear with me on this.

First, the way you’re handing checking the rotation is… hazardous, to say the least. floating point numbers will rarely be exactly equal to the value you want them to be, especially when that number is being approximated from a Quaternion rotation converted to Euler angles.

Based on your angle-to-vector conversions, you can also greatly simplify this, anyway:

``````direction = conveyorTransform.rotation * Vector3.back;
``````

Yep, that’s all. Vector3.back (0, 0, -1), rotated by multiplying it by the conveyor’s own rotation directly, will orient the direction vector on the same basis as your logic had been.

Next, there's your logic for applying force to objects on the conveyor belt. For one, rather than tracking the GameObject and getting a reference to its Rigidbody every frame, you'd be better off storing a list a Rigidbody components instead. Then, you can move them along the conveyor belt with drastically greater efficiency:
``````onBelt_.velocity = speed * direction;_
``````

Also, you don’t need to multiply their velocity by Time.deltaTime. Velocity is a measure of distance-per-second already.

As an additional note, since you’re also modifying forces applied to Rigidbodies (albeit by setting velocity directly rather than through Rigidbody.AddForce), you should probably have that running in FixedUpdate() rather than Update().

Finally, to address the errors you’d been getting…

direction = new Vector3(0, 0, -1);

You were missing the “new” keyword.

All in all, it looks like you should probably put in a bit more research on some of the basic principles in Unity. Most of the problems in this situation are specific to the game engine itself (although the basis for your question was generic).