- Home /
MouseY movement
Hi I would like to move my ship towards the Y axis of the mouse, i've checked the game input to mouseY
So far I have the code pasted below. Also a screenshot to elaborate this issue I have an object with no rotation but the camera is rotated -90 to show a side view. I have no gravity selected.
The top and bottom of the ship are in the scene editor 1.4 and -1.4 ( aka the min & max a ship could move thus its boundaries )
However the ship never reaches my max or min point as you can see in the screenshot. Its like it has a sort of delay or offset.
I am new to unity, i have many years of AS3 knowledge but awkwardly new to unity, but loving it! and so far I can't seem to bend my head around it. Thank you!
using UnityEngine;
using System.Collections;
[System.Serializable]
public class Boundary
{
public float xMin, xMax, zMin, zMax, yMin, yMax;
}
public class PlayerController : MonoBehaviour
{
public float speed;
public float tilt;
public Boundary boundary;
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("MouseY");
//float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (0.0f, moveHorizontal);
rigidbody.velocity = movement * speed;
rigidbody.position = new Vector3
(
0.0f,
Mathf.Clamp (rigidbody.position.y, boundary.yMin, boundary.yMax),
0.0f
);
rigidbody.rotation = Quaternion.Euler (0.0f,0.0f, rigidbody.velocity.y * -tilt );
}
}
![alt text][1] [1]: /storage/temp/27392-screenshot-2014-06-06-22.49.25.jpg
Answer by Dizzyman572 · Jun 06, 2014 at 10:46 PM
I've plugged in your code into unity and it seems that the code is working perfectly. I even played around with the settings and the cube never went past the min and max limit. Other than the cube jitterbugging a bit the code just seems fine in my perspective. Are you sure you didn't accidentally pressed "14" instead of "1.4" for min and max setting, that's the only possible fix I can up with. Or am I misinterpreting your problem entirely?
Your answer
Follow this Question
Related Questions
Diablo 3 like move to mouse (w/o click) - efficient? 1 Answer
How to make the mouse and light binding 0 Answers
Folow mouse script 0 Answers
Moving objects with *Isometric* mouse position (JS) 1 Answer