hello, i'm okay with the "ScreenToWorldPoint" error, but i am now moving the player depending on where the mouse position is.... and it works, he moves when the mouse moves, but he keeps resetting to the same "drag start" and i want each "drag start" to be where the current transform.position is, but i don't know how to do that... could someoen help me please?
EDIT: the COMPLETE script works... it's called FMoveAround, and the mouse "drag to move" kinda works: he moves exactly as i want, but he shifts from the place i want him, to some random place very far away, but the shifts are fast, kinda like a "every other frame he's where i want him to be" kind of thing.
here's my script:
function Update()
{
if(Input.GetKey(KeyCode.Mouse1))
{
transform.position.z += (Input.mousePosition.x + transform.position.z);
transform.position.y += (Input.mousePosition.y + transform.position.y);
}
print(Input.mousePosition);
}
any help is GREATLY apprecitaed! :)
Thank You very much!
p.s. Here's my COMPLETE script:
var HERE : Vector3;
var Val : int;
var cam : Camera;
var col : Color;
var Spike : Transform;
var work = true;
var cnt : int;
var Fast = false;
static var message : String = "My Words";
private var gravitySave : Vector3;
private var gravityOn = true;
var projectileSpeed : int = 105;
private var faster : int;
//vars
var Timer : int = 0;
var seconds : int = 0;
var minutes : int = 0;
var hours : int = 0;
var bullitPrefab : Transform;
var respawn1 : Vector3;
var respawn2 : Vector3;
var ctrl : int = 100;
var RespawnToHere : Vector3;
var Bspeed : int = 1500;
var fire = true;
var far : int;
//private vars
private var Respawn = true;//first respawn
private var auto = false; //auto move?
private var constant = false;
private var cont = false;
private var rad : int = 0;
//static vars
static var gotHit = false;
static var UseBetterBullet = false; //flamethrower
static var dead = false;//1st time dying
static var Dead = false;//2nd time dying
static var money = 0;
static var SCORE = 0;
function Awake()
{
HERE = transform.position;
}
//late update function that corrects anything that might need to be fixed before next script loop read.
function LateUpdate()
{
if(PlayerHeliPlayer.DoneFlying)
{
transform.position = RespawnToHere;
PlayerHeliPlayer.DoneFlying = false;
}
if(Dead && !Respawn) //second respawn
{
transform.position = respawn2;
Dead = false;
print("i respawned yet again!");
}
if(dead && Respawn) //first respawn
{//where the player respawns
transform.position = respawn1;
dead = false;
print("i respawned!");
}
}
//on trigger function for when player hits the specified triggers.
function OnTriggerEnter( hit : Collider )
{
if(hit.gameObject.tag == "SuddenDeath1")
{
enemyFollow.MOVE1 = false;
enemyFollow.MOVE2 = true;
enemyFollow.MOVE3 = false;
}
if(hit.gameObject.tag == "SuddenDeath2")
{
enemyFollow.MOVE1 = false;
enemyFollow.MOVE2 = false;
enemyFollow.MOVE3 = true;
}
if(hit.gameObject.tag == "MoneyMaker")
{
money += 50;
Destroy(hit.gameObject);
print("I have " +money+ " Dollars!");
}
if(hit.gameObject.tag == "fallout3" && !Respawn)
{
Dead = true;
HP.LIVES -= 1;
}
if(hit.gameObject.tag == "fallout2")
{
Respawn = false;
}
//when the player falls off (this doesnt really work too good. )
if(hit.gameObject.tag == "fallout")
{
dead = true;
//subtract life here
HP.LIVES -= 1;
print("i fell off...");
}
//getting hit (this works)
if(hit.gameObject.tag == "enemyProjectile")
{
gotHit = true;
HP.HITS += 1;
Destroy(hit.gameObject);
print("i got hit!");
}
//manipulating weather
if(hit.gameObject.tag == "weather")
{
ParticleEmitToggle.WCONTROL = true;
print("Now i can control weather.");
}
//level select button controls
if(hit.gameObject.tag == "Level2")
{
GUIshader.Level2 = true;
print("hit level two");
}
if(hit.gameObject.tag == "Level3")
{
GUIshader.Level3 = true;
print("hit level three");
}
if(hit.gameObject.tag == "Level4")
{
GUIshader.Level4 = true;
print("hit level four");
}
if(hit.gameObject.tag == "Level5")
{
GUIshader.Level5 = true;
print("hit level five");
}
if(hit.gameObject.tag == "WORK")
{
MovingPlatform4.work = true;
}
}
var Rect1 : Rect = Rect(50,46.20723,400,10);
var val1 : float = 5.259002;
var val2 : float = 198.4793;
var val3 : float = 5;
//GUI function to print the time the player spent playing && money && Orthographical_Zoom
function OnGUI()
{
GUI.contentColor = col;
GUI.Label(Rect(20,100, 400,30), "Play Time: " +hours * -1+" : "+minutes * -1+" : "+seconds * -1);
GUILayout.Label("Money: $" + money);
Camera.main.orthographicSize = GUI.HorizontalScrollbar(Rect1, Camera.main.orthographicSize, val1,val2,val3);
}
//code that will be read every loop (every frame)
function Update()
{
if(Input.GetKey(KeyCode.Mouse1))
{
transform.position.z += Input.mousePosition.x * 2;
transform.position.y += Input.mousePosition.y * 2;
}
print(Input.mousePosition);
if(Input.GetAxis("Mouse ScrollWheel"))
{
Camera.main.orthographic = true;
Camera.main.orthographicSize -= (Input.GetAxis("Mouse ScrollWheel") * 500) * Time.deltaTime;
print(Input.GetAxis("Mouse ScrollWheel"));
}
if(Input.GetKeyDown("left shift"))
{
cnt++;
}
if(cnt == 1)
{
faster = 2;
Fast = true;
}
if(cnt == 2)
{
faster = 0;
Fast = false;
}
if(cnt >= 3)
{
cnt = 0;
Fast = false;
}
if (Input.GetKey(KeyCode.Mouse0))
{
var ray = Camera.main.ScreenPointToRay (Input.mousePosition); // Construct a ray from the current mouse coordinates
var hit : RaycastHit;
if (Physics.Raycast (ray, hit))
{
Debug.DrawLine (Camera.main.transform.position, hit.point, Color.blue);
Debug.Log(hit.point);
var bullit = Instantiate (bullitPrefab, hit.point, transform.rotation); // Create a particle if hit
bullit.tag = "wormProjectile";
hit.transform.SendMessage("RCastHit", gameObject,SendMessageOptions.DontRequireReceiver);
}
}
if(Input.GetKeyDown(KeyCode.Delete)) // when the delete key is pressed
{
message = "Deleted"; // example word to be displayed. }
}
if(work)
{
if(transform.position.z >= far)
{
transform.position.z = far - 20;
}
if(transform.position.z <= (-1 * far))
{
transform.position.z = (far * -1) + 20;
}
}
Debug.Log(transform.position);
if(transform.position.x != 0)
{
transform.position.x = 0;
}
rigidbody.AddForce(0, ((Input.GetAxis("Vertical") * 500) * faster) * Time.deltaTime, ((Input.GetAxis("Horizontal") * 500) * faster) * Time.deltaTime);
Timer--;
if(Timer == -ctrl)
{
seconds --;
Timer = 0;
}
if(seconds == -60)
{
minutes--;
seconds = 0;
}
if(minutes == -60)
{
hours--;
minutes = 0;
}
if(hours == -25)
{
hours = 1;
}
//main menu button
if(Input.GetKeyDown("escape"))
{
Application.LoadLevel("Main Menu");
print("Main Menu Loading...");
}
//shooting
if(Input.GetKeyDown("f"))
{
if(!UseBetterBullet && !constant && fire)
{
//var bullit = Instantiate(bullitPrefab, gameObject.FindWithTag("SpawnPoint").transform.position,
//Quaternion.identity);
//bullit.tag = "wormProjectile";
//shoots it forward
//bullit.rigidbody.AddForce(0,0,Bspeed);
}
if(UseBetterBullet)
{
particleEmitter.emit = true;
Invoke("DestroyEmitter",1);
}
}
//prints your score
print("Score: "+SCORE);
//changes your score
switch(SCORE)
{
case 10:
Application.LoadLevel("Main Menu");
break;
}
}
//my function to destroy the flamethrower PE over time. PE = ParticleEmitter.
function DestroyEmitter()
{
if(Time.time*1.5 > 7.5)
particleEmitter.emit = false;
}