Moving a gameobject a set amount with a euler angle and distance as input

I’ve been googling and trying different approaches to this all night, but still don’t have a solid grasp of which functions to use.

I have a gameObject, that I don’t want to change to rotation of, but what to physically move in the world (x,y)

I have a euler angle of another gameObject that I want to move the target gameObject in (I have that gameobject too, if it helps)

I want to be able to specify an arbitrary force to move the gameObject to change its movement speed, or stop it

From what i’ve read and tried tonight I think a one liner should solve this, but its been beyond me to find it.

Thanks in advance for any help.

When you say “I have a euler angle of another gameObject that I want to move the target gameObject in” do you mean that you want to move your game object towards the other gameobject? If so you don’t want a rotation you want a direction.

(TargetGameObject.transform.position - CurrentGameObject.transform.position).normalized

Gives you a vector3 pointing in the direction from the 1st gameobject to the 2nd.

Currentobject.transform.position += Direction * Time.deltaTime * MovementSpeed

Will move the objects location in that direction without consideration for forces and physics.
If you want forces and physics then apply the movement through whatever rigid body or controller you have on the object.
i.e if you’re just using a rigidbody:

CurrentGameObjectRigidBody.AddForce(Direction * ForceMultiplier);

I want to move the target game object in the same direction the other gameobject is facing, so if the other game object is at 90 degrees, I want to move the target gameobject to the right, without rotating it

Then use the forward direction of the other gameobject for the movement direction. (transform.forward)

The gameObject is a vive controller, and It doesn’t have a forward vector on its transform unless i’m missing something.

    void Awake()
    {
        trackedObj = GetComponent<SteamVR_TrackedObject>();
    }
    void Update()
    {
        SteamVR_Controller.Device device = SteamVR_Controller.Input((int)trackedObj.index);
        float angle = device.transform.rot.eulerAngles.y;
        Debug.Log(angle); // shows the angle as I rotate the controller

    }

rotation and position are the only things It gives me to work with.

Ah, you didn’t mention you were talking about a Vive/VR controller, afraid i can’t help you much with specifics, no experience with vive/VR it and don’t have the stuff installed to poke around with it.

All gameobjects have a standard transform which includes a .forward, the standard transform also doesn’t have .rot.eulerAnglers (it’s just .eulerAngles). Suspecting that SteamVR_Controller.Device is not a unity gameobject/component and is using it’s own custom transform class. Afraid i can’t help you with whether there’s a normal way of getting a forward direction from your vive controller.

But it is possible to calculate a direction using eulerangles. Essentially you create a Quaternion rotation, and then use it to multiply some default base direction (Which i can’t tell you what is for Vive but is most likely vector3.Forward) in order to rotate it to point in the final direction

Quaternion Rotation = Quaternion.Euler(eulerAngles);
        Vector3 Direction = Rotation * Vector3.forward;

Beyond that, i’d just amend the thread title to be a little more descriptive that you’re trying to get the forward direction from a vive controller so you can try and get help from someone more knowledgeable about vive :wink:

I think That will give x,y,z and w rotations I only want to rotate around the y axis so should I use:

float yAngle = device.transform.rot.eulerAngles.y;
Quaternion Rotation = Quaternion.Euler(0,yAngle,0);
Vector3 Direction = Rotation * Vector3.forward;
Currentobject.transform.position += Direction *Time.deltaTime* MovementSpeed;

yes.

Again, I am of course assuming that the Euler angles that the vive controller is giving you represents a rotation from vector3.Forward.

This has me half way there. if I add 270 degrees to the angle, and hold the tip of the controller pointing in the direction I want to travel, I move in that direction now. With the vive controller oriented like this ( touchpad facing straight up):

x axis - tip up and down
y axis - controls direction of movement, where you point the handle, you go
z axis - controller roll

I need to change the whole transform about 90 degrees.
I want to stick the handle into the back of my belt, so movement will still happen in the direction the handle is pointing at, but the handle won’t be pointing straight at the object. I can’t just rotate a fixed value on the rotation variable, because then it sends the object into the air. the whole orientation of the controller needs adjusted for the calculation, which I am not sure what to use to do.

Thanks for the help so far btw :slight_smile: