Mouse Look на JS - Форум Игроделов
Вт, 04 Фев 2025, 03:07 
 
Приветствую Вас Гость Главная | Регистрация | Вход
Новые сообщения · Участники · Правила форума · Поиск · RSS ]
  • Страница 1 из 1
  • 1
Mouse Look на JS
GoodgeniusДата: Ср, 05 Фев 2014, 17:51 | Сообщение # 1
 
Сообщений: 86
Награды: 0
Репутация: 6
Статус: Offline
Сам нуждался в скрипте управления камерой на JS т.к. все пишу именно на этом языке.
Mouse Look:

Код
enum Axes {MouseXandY, MouseX, MouseY}
var Axis : Axes = Axes.MouseXandY;
   
var sensitivityX = 15.0;
var sensitivityY = 15.0;
   
var minimumX = -360.0;
var maximumX = 360.0;
   
var minimumY = -60.0;
var maximumY = 60.0;
   
var rotationX = 0.0;
var rotationY = 0.0;
   
var lookSpeed = 2.0;
      
function Update (){
if (Axis == Axes.MouseXandY)
{
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
Adjust360andClamp();
KeyLookAround();
KeyLookUp();
if (!Input.GetAxis("LookAround"))
{
transform.localRotation = Quaternion.AngleAxis (rotationX, Vector3.up);
}
if (!Input.GetAxis("LookUp"))
{
transform.localRotation *= Quaternion.AngleAxis (rotationY, Vector3.left);
}
}
else if (Axis == Axes.MouseX)
{
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
Adjust360andClamp();
KeyLookAround();
KeyLookUp();

if (!Input.GetAxis("LookAround"))
{
transform.localRotation = Quaternion.AngleAxis (rotationX, Vector3.up);
}
}
else
{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
Adjust360andClamp();
KeyLookAround();
KeyLookUp();

if (!Input.GetAxis("LookUp"))
{
transform.localRotation = Quaternion.AngleAxis (rotationY, Vector3.left);
}
}
}
   
function KeyLookAround ()
{
rotationX += Input.GetAxis("LookAround") * lookSpeed;
Adjust360andClamp();
transform.localRotation = Quaternion.AngleAxis (rotationX, Vector3.up);
}
   
function KeyLookUp ()
{
rotationY += Input.GetAxis("LookUp") * lookSpeed;
Adjust360andClamp();
transform.localRotation *= Quaternion.AngleAxis (rotationY, Vector3.left);
}
   
function Adjust360andClamp ()
{
if (rotationX < -360)
{
rotationX += 360;
}
else if (rotationX > 360)
{
rotationX -= 360;
}    

if (rotationY < -360)
{
rotationY += 360;
}
else if (rotationY > 360)
{
rotationY -= 360;
}
   
rotationX = Mathf.Clamp (rotationX, minimumX, maximumX);
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
}
   
function Start ()
{
if (rigidbody)
{
rigidbody.freezeRotation = true;
}
}
 
СообщениеСам нуждался в скрипте управления камерой на JS т.к. все пишу именно на этом языке.
Mouse Look:

Код
enum Axes {MouseXandY, MouseX, MouseY}
var Axis : Axes = Axes.MouseXandY;
   
var sensitivityX = 15.0;
var sensitivityY = 15.0;
   
var minimumX = -360.0;
var maximumX = 360.0;
   
var minimumY = -60.0;
var maximumY = 60.0;
   
var rotationX = 0.0;
var rotationY = 0.0;
   
var lookSpeed = 2.0;
      
function Update (){
if (Axis == Axes.MouseXandY)
{
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
Adjust360andClamp();
KeyLookAround();
KeyLookUp();
if (!Input.GetAxis("LookAround"))
{
transform.localRotation = Quaternion.AngleAxis (rotationX, Vector3.up);
}
if (!Input.GetAxis("LookUp"))
{
transform.localRotation *= Quaternion.AngleAxis (rotationY, Vector3.left);
}
}
else if (Axis == Axes.MouseX)
{
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
Adjust360andClamp();
KeyLookAround();
KeyLookUp();

if (!Input.GetAxis("LookAround"))
{
transform.localRotation = Quaternion.AngleAxis (rotationX, Vector3.up);
}
}
else
{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
Adjust360andClamp();
KeyLookAround();
KeyLookUp();

if (!Input.GetAxis("LookUp"))
{
transform.localRotation = Quaternion.AngleAxis (rotationY, Vector3.left);
}
}
}
   
function KeyLookAround ()
{
rotationX += Input.GetAxis("LookAround") * lookSpeed;
Adjust360andClamp();
transform.localRotation = Quaternion.AngleAxis (rotationX, Vector3.up);
}
   
function KeyLookUp ()
{
rotationY += Input.GetAxis("LookUp") * lookSpeed;
Adjust360andClamp();
transform.localRotation *= Quaternion.AngleAxis (rotationY, Vector3.left);
}
   
function Adjust360andClamp ()
{
if (rotationX < -360)
{
rotationX += 360;
}
else if (rotationX > 360)
{
rotationX -= 360;
}    

if (rotationY < -360)
{
rotationY += 360;
}
else if (rotationY > 360)
{
rotationY -= 360;
}
   
rotationX = Mathf.Clamp (rotationX, minimumX, maximumX);
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
}
   
function Start ()
{
if (rigidbody)
{
rigidbody.freezeRotation = true;
}
}

Автор - Goodgenius
Дата добавления - 05 Фев 2014 в 17:51
  • Страница 1 из 1
  • 1
Поиск:
Загрузка...

Game Creating CommUnity © 2009 - 2025