How to rotate one object depending on rotation for another?[advanced]

Hello,

I made steering wheel that rotates infinity as boat steering wheel.

wheel.transform.rotation = Quaternions.Euler(0, angle, 0);

this work fine.

Than add object that use same angle but I want so it will rotate much slowly like 2 full spins wheel = 1 spin object;

how realize this? I broke my brain...

Boat steering wheel rotates from 0 to 360 degrees. If I simple devide it by 2, I will get issue and this is correct but not that what I'm looking for.

other words I want like this:

1 wheel spin = 0.5 object spin, 2 spin = 1 spin

var angle : float = wheel_angle / 2;

made issue because when I get 360 degress - my object reset rotation again from 0 too.... so I always get like 0-360 wheel = 0-180 object (

damn I can't say that I want (((

It’s probably easier to use the delta. Instead of worrying about absolute rotation, just rotate the rudder (or whatever) by half the amount that the wheel rotates each frame.

This isn’t advanced.

When you read the calculate the rotational delta of Obj A just apply one half of that to Obj B.

Ok, here is my sources ( I don’t post all variables declarations) just ObjB it’s mycube

private var mycube:GameObject = null;

function Start ()
{
mycube = GameObject.Find(‘Cube’);
}

function OnMouseUp(){

isMouseDown = false;

}

function OnMouseDown(){
old_rotations = transform.rotation.eulerAngles.z;

var screenPos_OLD:Vector3 = Camera.allCameras[1].WorldToScreenPoint(transform.position);
var deltaX_OLD:float = Input.mousePosition.x - screenPos_OLD.x;
var deltaY_OLD:float = Input.mousePosition.y - screenPos_OLD.y;
var radians_OLD:float = Mathf.Atan2( deltaY_OLD, deltaX_OLD);
degress_OLD = (radians_OLD * 180 ) / Mathf.PI;

isMouseDown = true;

}

function OnMouseDrag (){
if ( isMouseDown ) {

var screenPos_NEW:Vector3 = Camera.allCameras[1].WorldToScreenPoint(transform.position);
var deltaX_NEW:float = Input.mousePosition.x - screenPos_NEW.x;
var deltaY_NEW:float = Input.mousePosition.y - screenPos_NEW.y;
var radians_NEW:float = Mathf.Atan2( deltaY_NEW, deltaX_NEW);

var degress_NEW:float = (radians_NEW * 180 ) / Mathf.PI;

var delta_angles:float = degress_NEW - degress_OLD;
var targetAngle : float = old_rotations - delta_angles;

transform.rotation = Quaternion.Euler(0,180, targetAngle);

rudder_angle= transform.eulerAngles.z;
mycube.transform.rotation = Quaternion.Euler ( 0, rudder_angle, 0 );

}

}

Last lines it’s angles from 0 to 360 of rudder and mycube it’s another object. For example - boat.

when my rudder goes from 360 to 0 - by boat stops on 180 and than resets to 0 again I will use this rudder_angle= transform.eulerAngles.z / 2;

what about addeding on OnMouseDrag I don’t know. When mouse down it’s work as Update each frame (

please help.

I’m not Unity3D developer, I convert this code from Flash ActionScript 3.0, where I’m more brained )
In AS3 I done this in a few minutes because there don’t unsed any Euler angles ((((

Any help?

Wow ,amazing

so ) what with helping? )))

Use your own variable (e.g. rudder_angle) - which must not be overwritten by a transform - to store the angle even beyond 360…
Then just set the rotation using “rudder_angle % 360” or if you want to apply only the half “(rudder_angle / 2) % 360”

P.S. this thread should be labelled “beginner”, not “advanced”

I can’t figureout this…

I can’t get angle beyound 360 because my rudder return delta so I rotate it around to infinity

When I get targetAngle that also receiving my rudder - its from -90 to 270 fixed! I know this from Debug.Log

Step 2 I know, I do right away in anther 3D engine. But what should be in step 1 - I can’t understand … damn… All people said strange words about transforms and etc but I can’t understand how this must be applied in my code above

I can think of some other descriptions for the title.

Stop Making this so hard for yourself…

You can figure out the rotation amount using your mouse drag, but here is a basic script that will rotate your rudder and steering wheel using Left/Right Arrows…

I might get the syntax wrong since I dont bother with JS, but here goes… I may also be rotating the rudder backwards… if so, just swap the left and right rotation code… I may also be rotating around the wrong axis, again, just move the rotation code into the correct XYZ

var SteeringWheel : Transform;
var Rudder : Transform;

var TurnRate : float = 5;
var MaximumRudder : float = 30;

function Update()
{
  var rudderRotation : float = Rudder.localEulerAngles.y; 

  if(Input.GetKey(KeyCode.LeftArrow))  {
        SteeringWheel.Rotate(-TurnRate * Time.deltaTime,0,0);
        if(rudderRotation < 180  rudderRotation < MaximumRudder)
             Rudder.Rotate(0, TurnRate * Time.deltaTime * 0.5f,0);

  } else if(Input.GetKey(KeyCode.RightArrow))  {
        SteeringWheel.Rotate(TurnRate * Time.deltaTime,0,0);
        if(rudderRotation > 180  rudderRotation > 360-MaximumRudder)
             Rudder.Rotate(0, -TurnRate * Time.deltaTime * 0.5f,0);

  }


}