Updated question to better describe needs/intentions in a new query.
Moving a character with touch controls relative to target?
16-02-2016
I have since reworked my controls to raycast on to the scene and the player moves towards that. This is still not my preferred method of movement, but I will be closing this question to link to a more descriptive question that explains better my intentions or needs. Thank you for the support. http://answers.unity3d.com/questions/1141246/how-can-i-get-vector-coordinates-from-a-raycast-re.html
~hy
Hello,
I am building a game where the camera is at a fixed position, rotation, etc. from a character. The camera is simply given a position offset from the character object. I have built controls to move this character based on the screen position of an input. This began to slowly fall apart as I have been unable to come up with a way to arbitrarily modify the origin of the movement.
I need a way to either:
-move the character relative to the centre of the screen
-move the character relative to its current position
At the moment it:
-moves relative to 0-1 scale screen coordinates (bottom-left is 0,0; top-right is 1,1)
-will only move left and downwards normally (the inverse of the screen's y-coordinate)
If a code sample is needed, here is the section of trouble (C#):
public float walk = 12f;
void Update(){
if( (INPUT CONDITIONS) ){
#if (UNITY_EDITOR || UNITY_STANDALONE)
mdown = Camera.main.ScreenPointToRay(Input.mousePosition);
#elif (UNITY_ANDROID || UNITY_IPHONE)
mdown = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
#endif
RaycastHit mpointhit;
if(Physics.Raycast(mdown, out mpointhit)){
mpoint.x = mpointhit.point.x;
mpoint.z = mpointhit.point.z;
move = new Vector3(mpoint.x, 0, mpoint.z);
move *= walk;
}
}
user.transform.position += move*Time.deltaTime;
}
I have taken out sections of comments and attempts to "reposition" the origin of movement, which included using Camera.main.pixelRect.center.
Thank you
Follow this Question
Related Questions
First person movement with character controller does not detect ground properly 0 Answers
Problem with the Character Controller on the Y-Axis,Character Controller drifting in the Y Axis 0 Answers
Jump logic issues 0 Answers
CharacterController.Move with slow animals - they do not move 1 Answer
Help converting a character controller script to rigidbody 1 Answer