I’m trying to copy the movement from the hand in Black & White 2 and have been struggling the last 2 days. I’ve done a lot of research over 2 days worth but am still having the problem. I basically wanna copy the movement in the video below but have no clue how to reference it. I’ve been using the code below but basically it move’s on the Y axis whenever I want it to only move on X & Z. The main issue is it goes up on the y axis instead of forward
TLDR
What I got now What I got so far - Album on Imgur
What I’m trying to do Movement Example - Album on Imgur
using UnityEngine;
using System.Collections;
public class MagicGodHand : MonoBehaviour
{
public float horizontalSpeed = 2.0F;
public float verticalSpeed = 2.0F;
private void Start()
{
Cursor.visible = false;
}
void Update()
{
if (Input.GetKey(KeyCode.Mouse2))
{
float h = horizontalSpeed * Input.GetAxis("Mouse X");
float v = verticalSpeed * Input.GetAxis("Mouse Y");
}
}
{
Vector3 temp = Input.mousePosition;
temp.z = 30f; // Set this to be the distance you want the object to be placed in front of the camera.
this.transform.position = Camera.main.ScreenToWorldPoint(temp);
}
}
Bonus Points : My camera also moves on the Y using the code below but I would prefer it to move like in the video and go forward on the Z instead of moving on a Y. I’ll pay if someone can solve this for me. I’ll put my camera code below. I’ve tried a million different things with the camera but am still unable to resolve it as well. I’ve tried all the .transforms but am unsucessful . The only thing wrong with my camera is it zooms in on w instead of moving in the map like on the imgur link. Here is my code for the camera
using UnityEngine;
[RequireComponent(typeof(Camera))]
public class DrakeCamera : MonoBehaviour
{
#region UI
[Space]
[SerializeField]
private bool _active = true;
[Space]
[SerializeField]
private bool _enableRotation = true;
[SerializeField]
private float _mouseSense = 1.8f;
[Space]
[SerializeField]
private bool _enableTranslation = true;
[SerializeField]
private float _translationSpeed = 55f;
[Space]
[SerializeField]
private bool _enableMovement = true;
[SerializeField]
private float _movementSpeed = 10f;
[SerializeField]
private float _boostedSpeed = 50f;
[Space]
[SerializeField]
private bool _enableSpeedAcceleration = true;
[SerializeField]
private float _speedAccelerationFactor = 1.5f;
[Space]
[SerializeField]
private KeyCode _initPositonButton = KeyCode.R;
#endregion UI
private CursorLockMode _wantedMode;
private float _currentIncrease = 1;
private float _currentIncreaseMem = 0;
private Vector3 _initPosition;
private Vector3 _initRotation;
#if UNITY_EDITOR
private void OnValidate()
{
if (_boostedSpeed < _movementSpeed)
_boostedSpeed = _movementSpeed;
}
#endif
private void Start()
{
_initPosition = transform.position;
_initRotation = transform.eulerAngles;
}
private void CalculateCurrentIncrease(bool moving)
{
_currentIncrease = Time.deltaTime;
if (!_enableSpeedAcceleration || _enableSpeedAcceleration && !moving)
{
_currentIncreaseMem = 0;
return;
}
_currentIncreaseMem += Time.deltaTime * (_speedAccelerationFactor - 1);
_currentIncrease = Time.deltaTime + Mathf.Pow(_currentIncreaseMem, 3) * Time.deltaTime;
}
private void Update()
{
if (!_active)
return;
// Translation
if (_enableTranslation)
{
transform.Translate(Vector3.forward * Input.mouseScrollDelta.y * Time.deltaTime * _translationSpeed);
}
// Movement
if (_enableMovement)
{
Vector3 deltaPosition = Vector3.zero;
float currentSpeed = _movementSpeed;
if (Input.GetKey(KeyCode.LeftShift))
currentSpeed = _boostedSpeed;
if (Input.GetKey(KeyCode.W))
deltaPosition += transform.forward;
if (Input.GetKey(KeyCode.S))
deltaPosition -= transform.forward;
if (Input.GetKey(KeyCode.A))
deltaPosition -= transform.right;
if (Input.GetKey(KeyCode.D))
deltaPosition += transform.right;
// Calc acceleration
CalculateCurrentIncrease(deltaPosition != Vector3.zero);
transform.position += deltaPosition * currentSpeed * _currentIncrease;
}
// Rotation
if (Input.GetKey(KeyCode.Mouse2))
{
// Pitch
transform.rotation *= Quaternion.AngleAxis(
-Input.GetAxis("Mouse Y") * _mouseSense,
Vector3.right
);
// Paw
transform.rotation = Quaternion.Euler(
transform.eulerAngles.x,
transform.eulerAngles.y + Input.GetAxis("Mouse X") * _mouseSense,
transform.eulerAngles.z
);
}
// Return to init position
if (Input.GetKeyDown(_initPositonButton))
{
transform.position = _initPosition;
transform.eulerAngles = _initRotation;
}
}
}
i