Converting AimLookCharacterController.cs to Javascript

I am trying to use the AimLookCharacterController.cs that comes with the Locomotion System. But I need it in Javascript instead of C#. I couldn’t figure out how to do that exactly:

using UnityEngine;
using System.Collections;

public class AimLookCharacterController : MonoBehaviour {
	
	private CharacterMotor motor;
	
	// Use this for initialization
	void Start () {
		motor = GetComponent(typeof(CharacterMotor)) as CharacterMotor;
		if (motor==null) Debug.Log("Motor is null!!");
		
		//originalRotation = transform.localRotation;
	}
	
	// Update is called once per frame
	void Update () {
		// Get input vector from kayboard or analog stick and make it length 1 at most
		Vector3 directionVector = new Vector3(Input.GetAxis("Horizontal2"), Input.GetAxis("Vertical2"), 0);
		if (directionVector.magnitude>1) directionVector = directionVector.normalized;
		
		// Rotate input vector into camera space so up is camera's up and right is camera's right
		directionVector = Camera.main.transform.rotation * directionVector;
		
		
		
		// Rotate input vector to be perpendicular to character's up vector
		Quaternion camToCharacterSpace = Quaternion.FromToRotation(Camera.main.transform.forward*-1, transform.up);
		directionVector = (camToCharacterSpace * directionVector);
		
		// Apply direction
		motor.desiredFacingDirection = directionVector;
	}
}

Hi, welcome to the forum!

You can actually call the C# routines from JavaScript, but you should put the C# files into the Standard Assets folder so that they compile first. If you need the conversion to JS in order to modify the code, then could you explain what specific problems you are having?

Hi andeeee,

Thanks for the welcome!

What I am trying to is to create a control and camera system which accomplishes the following:
1- Camera orbit around the player, movement is relative to the screen (I managed to do this through using the Lerps third person tutorial.

2- When the player hits the right mouse button to go into aiming mode three things happen:
A- The character turns to face the upper side of the screen.
B- The camera zooms in to an Over the Shoulder perspective.
C- Character movement becomes player relative (left and right will strafe into that direction, up moves forward and back moves backward)

Now the script in my first post is the closer result I found to achive the character turning toward the upper side but the problem is that it is in C# while everything else is in Javascript. Even though I can execute it, I don’t know how to script in C# to control the other features (camera zoom for instance). The other problem, I am not sure how to make it work with the Lerps third person controller because it currently assumes a character motor specific to the locomotion system.

Quick C#-JS conversion rundown…

You don’t need the “using” lines or the “public class…” at the start. Variables in C# are declared with the type name first, then the name of the variable, so something like:-

Vector3 point;

…is rendered as

var point: Vector3;

…in JS.

Similarly, C# functions are written with the type name at the start, so:-

void Update() { ...

…is equivalent to JS’s

function Update() {...

Most other syntax is very similar between the two languages, so a lot of C# is actually valid JS too.