Character Turning error?

so, i’ve been reworking the character movement script, adapted from the standard assets 3rd person controller… and i’m trying to get it so that when the mouse is held down, the turning towards what you’re clicking on takes precidence over the previous orientation… but, i’m lost as to where it is? i’m trying to figure it out but i’m having a sort of blonde moment here.

here’s what i’ve got so far for scripting.

var speed = 3.0;
var jumpSpeed = 8.0;
var gravity = 20.0;

var smoothSpeed = 10.0;
var smoothDirection = 10.0;

var canJump = true;

var target : Transform;
var reticle1 : Transform;
var reticle2 : Transform;
var turnSpeedClick = 15.0;
var playerInitialOrientation;

private var moveDirection = Vector3.zero;
private var verticalSpeed = 0.0;
private var moveSpeed = 0.0;

private var grounded : boolean = false;
private var jumping : boolean = false;

private var targetAngle = 0.0;

// Require a character controller to be attached to the same game object
@script RequireComponent(CharacterController)

function Awake ()
{
	moveDirection = transform.TransformDirection(Vector3.forward);
}

function UpdateSmoothedMovementDirection ()
{
	var cameraTransform = Camera.main.transform;
	
	// Forward vector relative to the camera along the x-z plane	
	var forward = cameraTransform.TransformDirection(Vector3.forward);
	forward.y = 0;
	forward = forward.normalized;
	// Right vector relative to the camera
	// Always orthogonal to the forward vector
	var right = Vector3(forward.z, 0, -forward.x);

	// Target direction relative to the camera
	var targetDirection = Input.GetAxis("Horizontal") * right + Input.GetAxis("Vertical") * forward;
	
	// We store speed and direction seperately,
	// so that when the character stands still we still have a valid forward direction
	// moveDirection is always normalized, and we only update it if there is user input.
	if (targetDirection != Vector3.zero)
	{
		moveDirection = Vector3.Lerp(moveDirection, targetDirection, smoothDirection * Time.deltaTime);
		moveDirection = moveDirection.normalized;
	}

	// Smooth the speed based on the current target direction
	var curSmooth = smoothSpeed * Time.deltaTime;
	// When in air we accelerate slower
	if (!grounded)
	{
		curSmooth *= 0.5;
	}

	moveSpeed = Mathf.Lerp(moveSpeed, targetDirection.magnitude * speed, curSmooth);
}

function Update() {

	// Generate a plane that intersects the transform's position with an upwards normal.
    var playerPlane = new Plane(Vector3.up, transform.position);
    var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
	var hitdist = 0.0;
    
	
	UpdateSmoothedMovementDirection();

	if (grounded) {
		verticalSpeed = 0.0;
		
		// Jump		
		if (canJump  Input.GetButton ("Jump")) {
			verticalSpeed = jumpSpeed;
			jumping = true;
			SendMessage("DidJump", SendMessageOptions.DontRequireReceiver);
		}
	}
	// Apply gravity
	verticalSpeed -= gravity * Time.deltaTime;
	
	var movement = moveDirection * moveSpeed + Vector3 (0, verticalSpeed, 0);
	movement *= Time.deltaTime;
	
	// Move the controller
	var controller : CharacterController = GetComponent(CharacterController);
	var flags = controller.Move(movement);
	grounded = (flags  CollisionFlags.CollidedBelow) != 0;

	// Set rotation to the move direction	
	transform.rotation = Quaternion.LookRotation(moveDirection);
	
	// We are in jump mode but just became grounded
	if (grounded  jumping)
	{
		jumping = false;
		SendMessage("DidLand", SendMessageOptions.DontRequireReceiver);
	}
	
	// If the ray is parallel to the plane, Raycast will return false.
    if (playerPlane.Raycast (ray, hitdist)) 
	{
        // Get the point along the ray that hits the calculated distance.
        var targetPoint = ray.GetPoint(hitdist);
		
		//reticleCache = targetPoint;
		targetCache = GameObject.FindWithTag("Player").transform;
		
		//print(reticleCache);
		//var isClickingLeft = false;
        // Determine the target rotation.  This is the rotation if the transform looks at the target point.
        var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
       
        // if Mouse click is held down, Smoothly rotate towards the target point.
        if (Input.GetMouseButton(0))
		{
			transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, turnSpeedClick * Time.deltaTime);
			reticle1.transform.position = targetPoint;
			print(targetPoint);
		}
		if (Input.GetMouseButton(0)==false)
		{
			reticle1.transform.position = target.transform.position;
			
		}
		if (Input.GetMouseButton(1))
		{
			transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, turnSpeedClick * Time.deltaTime);
			reticle2.transform.position = targetPoint;
			print(targetPoint);
		}
		if (Input.GetMouseButton(1)==false)
		{
			reticle2.transform.position = target.transform.position;
			
		}
	}	
}

function GetSpeed () {
	return moveSpeed;
}

function IsJumping () {
	return jumping;
}

function GetDirection () {
	return moveDirection;
}

i’m not a good coder, my forte is in the graphics department… so please understand that i’m not all that great with coding.

Can you repost your code using ‘code’ tags instead of ‘quote’ tags?

There you go.

var speed = 3.0;
var jumpSpeed = 8.0;
var gravity = 20.0;

var smoothSpeed = 10.0;
var smoothDirection = 10.0;

var canJump = true;

var target : Transform;
var reticle1 : Transform;
var reticle2 : Transform;
var turnSpeedClick = 15.0;
var playerInitialOrientation;

private var moveDirection = Vector3.zero;
private var verticalSpeed = 0.0;
private var moveSpeed = 0.0;

private var grounded : boolean = false;
private var jumping : boolean = false;

private var targetAngle = 0.0;

// Require a character controller to be attached to the same game object
@script RequireComponent(CharacterController)

function Awake ()
{
moveDirection = transform.TransformDirection(Vector3.forward);
}

function UpdateSmoothedMovementDirection ()
{
var cameraTransform = Camera.main.transform;

// Forward vector relative to the camera along the x-z plane 
var forward = cameraTransform.TransformDirection(Vector3.forward );
forward.y = 0;
forward = forward.normalized;
// Right vector relative to the camera
// Always orthogonal to the forward vector
var right = Vector3(forward.z, 0, -forward.x);

// Target direction relative to the camera
var targetDirection = Input.GetAxis("Horizontal") * right + Input.GetAxis("Vertical") * forward;

// We store speed and direction seperately,
// so that when the character stands still we still have a valid forward direction
// moveDirection is always normalized, and we only update it if there is user input.
if (targetDirection != Vector3.zero)
{
moveDirection = Vector3.Lerp(moveDirection, targetDirection, smoothDirection * Time.deltaTime);
moveDirection = moveDirection.normalized;
}

// Smooth the speed based on the current target direction
var curSmooth = smoothSpeed * Time.deltaTime;
// When in air we accelerate slower
if (!grounded)
{
curSmooth *= 0.5;
}

moveSpeed = Mathf.Lerp(moveSpeed, targetDirection.magnitude * speed, curSmooth);
}

function Update() {

// Generate a plane that intersects the transform's position with an upwards normal.
var playerPlane = new Plane(Vector3.up, transform.position);
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hitdist = 0.0;


UpdateSmoothedMovementDirection();

if (grounded) {
verticalSpeed = 0.0;

// Jump 
if (canJump  Input.GetButton ("Jump")) {
verticalSpeed = jumpSpeed;
jumping = true;
SendMessage("DidJump", SendMessageOptions.DontRequireReceiver);
}
}
// Apply gravity
verticalSpeed -= gravity * Time.deltaTime;

var movement = moveDirection * moveSpeed + Vector3 (0, verticalSpeed, 0);
movement *= Time.deltaTime;

// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(movement);
grounded = (flags  CollisionFlags.CollidedBelow) != 0;

// Set rotation to the move direction 
transform.rotation = Quaternion.LookRotation(moveDirection);

// We are in jump mode but just became grounded
if (grounded  jumping)
{
jumping = false;
SendMessage("DidLand", SendMessageOptions.DontRequireReceiver);
}

// If the ray is parallel to the plane, Raycast will return false.
if (playerPlane.Raycast (ray, hitdist)) 
{
// Get the point along the ray that hits the calculated distance.
var targetPoint = ray.GetPoint(hitdist);

//reticleCache = targetPoint;
targetCache = GameObject.FindWithTag("Player").transform;

//print(reticleCache);
//var isClickingLeft = false;
// Determine the target rotation. This is the rotation if the transform looks at the target point.
var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);

// if Mouse click is held down, Smoothly rotate towards the target point.
if (Input.GetMouseButton(0))
{
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, turnSpeedClick * Time.deltaTime);
reticle1.transform.position = targetPoint;
print(targetPoint);
}
if (Input.GetMouseButton(0)==false)
{
reticle1.transform.position = target.transform.position;

}
if (Input.GetMouseButton(1))
{
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, turnSpeedClick * Time.deltaTime);
reticle2.transform.position = targetPoint;
print(targetPoint);
}
if (Input.GetMouseButton(1)==false)
{
reticle2.transform.position = target.transform.position;

}
} 
}

function GetSpeed () {
return moveSpeed;
}

function IsJumping () {
return jumping;
}

function GetDirection () {
return moveDirection;
}

Hmmm… 3rd post today I have seen really asking the same question. How do I get something to point to where I click on the screen.

In your case, you want the 3d point where it lands.

var ray = Camera.main.ScreenPointToRay (Input.mousePosition);

var hit : RaycastHit;
if (Physics.Raycast (Camera.main.transform.position, ray, hit)) {
//do something with the point that we have in hit.point.....
}

Now you want to basically slerp to the rotation while the button is down, or just do it automatically

well, i’ve been able to work out the code to make it turn in previous scripts which i’ve learned from and also cannibalized, and i’m sure that if i put a conditional statement in the if-statement for the “turn towards what direction you’re going” to make it do a check for if one of the mouse buttons is currently pressed… thing is, i’m at a loss as to where to put it.

it seems like it would be a simple fix, but since i’m not really all that good at coding, i’m scratching my head going “well, i know what to do but where do i put it?”

as the code stands right now, if i try and use the mouseclick feature, it looks like it’s fighting between two slerp functions… so, to me that says that they ARE working, just, they’re working against eachother.

i guess this is one of the down-sides to being the graphics guy and not having the coding mindset. (it’s basically mostly greek to me.)

found it…

In one part you have:

// Set rotation to the move direction 
transform.rotation = Quaternion.LookRotation(moveDirection);

The next you have:

// if Mouse click is held down, Smoothly rotate towards the target point.
if (Input.GetMouseButton(0))
{
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, turnSpeedClick * Time.deltaTime);
reticle1.transform.position = targetPoint;
print(targetPoint);
}
if (Input.GetMouseButton(0)==false)
{
reticle1.transform.position = target.transform.position;

}
if (Input.GetMouseButton(1))
{
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, turnSpeedClick * Time.deltaTime);
reticle2.transform.position = targetPoint;
print(targetPoint);
}
if (Input.GetMouseButton(1)==false)
{
reticle2.transform.position = target.transform.position;

}

You are setting your rotation twice, hence it looks like it’s freaking out.

And lastly, I tinkered with the script to make it run. I don’t really understand the concept of why you want to have 2 reticules up but it does work…

var speed = 3.0;
var jumpSpeed = 8.0;
var gravity = 20.0;

var smoothSpeed = 10.0;
var smoothDirection = 10.0;

var canJump = true;

var target : Transform;
var reticle1 : Transform;
var reticle2 : Transform;
var turnSpeedClick = 15.0;
var playerInitialOrientation;
private var ret1pos;
private var ret2pos;

private var moveDirection = Vector3.zero;
private var verticalSpeed = 0.0;
private var moveSpeed = 0.0;

private var grounded : boolean = false;
private var jumping : boolean = false;

private var targetAngle = 0.0;

// Require a character controller to be attached to the same game object
@script RequireComponent(CharacterController)

function Awake ()
{
	moveDirection = transform.TransformDirection(Vector3.forward);
}

function UpdateSmoothedMovementDirection ()
{
	var cameraTransform = Camera.main.transform;

	// Forward vector relative to the camera along the x-z plane 
	var forward = cameraTransform.TransformDirection(Vector3.forward );
	forward.y = 0;
	forward = forward.normalized;
	// Right vector relative to the camera
	// Always orthogonal to the forward vector
	var right = Vector3(forward.z, 0, -forward.x);

	// Target direction relative to the camera
	var targetDirection = Input.GetAxis("Horizontal") * right + Input.GetAxis("Vertical") * forward;

	// We store speed and direction seperately,
	// so that when the character stands still we still have a valid forward direction
	// moveDirection is always normalized, and we only update it if there is user input.
	if (targetDirection != Vector3.zero)
	{
		moveDirection = Vector3.Lerp(moveDirection, targetDirection, smoothDirection * Time.deltaTime);
		moveDirection = moveDirection.normalized;
	}

	// Smooth the speed based on the current target direction
	var curSmooth = smoothSpeed * Time.deltaTime;
	// When in air we accelerate slower
	if (!grounded)
	{
		curSmooth *= 0.5;
	}

	moveSpeed = Mathf.Lerp(moveSpeed, targetDirection.magnitude * speed, curSmooth);
}

function Update() {
	

	UpdateSmoothedMovementDirection();

	if (grounded) {
		verticalSpeed = 0.0;

		// Jump 
		if (canJump  Input.GetButton ("Jump")) {
			verticalSpeed = jumpSpeed;
			jumping = true;
			SendMessage("DidJump", SendMessageOptions.DontRequireReceiver);
		}
	}
	// Apply gravity
	verticalSpeed -= gravity * Time.deltaTime;

	var movement = moveDirection * moveSpeed + Vector3 (0, verticalSpeed, 0);
	movement *= Time.deltaTime;

	// Move the controller
	var controller : CharacterController = GetComponent(CharacterController);
	var flags = controller.Move(movement);
	grounded = (flags  CollisionFlags.CollidedBelow) != 0;

	// Set rotation to the move direction 
	//transform.rotation = Quaternion.LookRotation(moveDirection);

	// We are in jump mode but just became grounded
	if (grounded  jumping){
		jumping = false;
		SendMessage("DidLand", SendMessageOptions.DontRequireReceiver);
	}
	
	// dont generate plane hit math unless a mouse button is down
	if (Input.GetMouseButton(0) || Input.GetMouseButton(1)) 
	{
		// Generate a plane that intersects the transform's position with an upwards normal.
		var playerPlane = new Plane(Vector3.up, transform.position);
		var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
		var hitdist = 0.0;
		
		if (playerPlane.Raycast (ray, hitdist)) {
			// Get the point along the ray that hits the calculated distance.
			var targetPoint = ray.GetPoint(hitdist);

			// Determine the target rotation. This is the rotation if the transform looks at the target point.
			var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);

			// if Mouse click is held down, Smoothly rotate towards the target point.
			if (Input.GetMouseButton(0))
			{
				transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, turnSpeedClick * Time.deltaTime);
				ret1pos = targetPoint;
			}else if (Input.GetMouseButton(1))
			{
				transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, turnSpeedClick * Time.deltaTime);
				ret2pos = targetPoint;
			}
		}
	}
	if(ret1pos!=null){
		reticle1.transform.position = ret1pos;
		reticle1.renderer.enabled=true;
	}
	if(ret2pos!=null){
		reticle2.transform.position = ret2pos;
		reticle2.renderer.enabled=true;
	}
}

function GetSpeed () {
	return moveSpeed;
}

function IsJumping () {
	return jumping;
}

function GetDirection () {
	return moveDirection;
}

well, the two reticles are more for things where combining button one and two together… though, all things considered, i’m very tempted to scrap that (i.e. using a pyrokinesis ability with an aerokinesis ability to make a piller of fire or something like that.)

thank you for the assist. i’ll definately check it out and try to learn from this. (it’s slow going but at the least Java isn’t so difficult to learn… just, it’s a lot to take in at once.)

okay, tested and i can’t say that it’s totally solved yet… it seems to want to turn only with the mouse now.

i’ll see about trying to figure this one out and trying to determine where i’m going to have to put in that “if mouse is clicked” conditional statement. thank you though.

as the green goblin once said… “Back to formula?!” i think it’s going to come to that as well.

so, here’s the starter script that i’m going to use and see about integrating the “rotate character in the direction you’re going” part.

var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 10.0;

private var moveDirection : Vector3 = Vector3.zero;

function Update() {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;

if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}




// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;

// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}

it’s cobbled together from scripts found here and on answers (and it isn’t overly complex.)

so, what i was wondering… do you think i should work on integrating the mouselook feature first and then the “slerp towards direction you’re going” function or vice versa? maybe both at the same time?

forgiveness is asked since i’m still noobish here and as much as i am learning more, a lot of this is a bit over my head.

okay… so, i have worked out that there are going to be two main conditions… wether mouse is clicked and wether it is not… that should help clean up the code just a little bit.

thing is, aside from the 3rd person controller (which has it’s bugs such as when you head one direction then go the opposite it trails forward before turning) i’m thinking that a lack of slerping/lerping (still new to which is which) towards the direction and just “Face direction pressed” option. thing is, aside from 8 separate conditional statements and hard-coding the orientation, anyone know of a quicker and simpler (more elegant) way of doing that?

(also going to make sure this script is shared… i’m sure that i’m not the only one that would want something like this in their library of possible scripts to use.)

Hey there… been working on trying to incorporate this and i’ve come up against a bug that i’m at a loss to explain (if someone can explain… not just post code, that way i can learn a bit better)

//LIST OF THINGS TO DO
/*
1. create two conditional statements to read wether the mouse is or not clicked.
2. create mouseclick feature inside conditional statements
3. create orientation override in conditional statements
*/

var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 10.0;
var reticle1 : Transform;
var target : Transform;
private var moveDirection : Vector3 = Vector3.zero;

function Update() {
//grab the Character controller
var controller : CharacterController = GetComponent(CharacterController);

//Code for Plane generation for mouseclick
var playerPlane = new Plane(Vector3.up, transform.position);
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hitdist = 0.0;
// If the ray is parallel to the plane, Raycast will return false.
    if (playerPlane.Raycast (ray, hitdist)) 
	{
        // Get the point along the ray that hits the calculated distance.
        var targetPoint = ray.GetPoint(hitdist);
		
		//reticleCache = targetPoint;
		targetCache = GameObject.FindWithTag("Player").transform;
		
		//print(reticleCache);
		//var isClickingLeft = false;
        // Determine the target rotation.  This is the rotation if the transform looks at the target point.
        var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
       
	}
//test to see if Character is on the ground or not.
if (controller.isGrounded) {
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
debug = "vertical";



if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}

if (Input.GetMouseButton(0))
		{
			transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, speed * Time.deltaTime);
			reticle1.transform.position = targetPoint;
			print(targetPoint);
		}

if (Input.GetMouseButton(0)==false)
		{
			reticle1.transform.position = target.transform.position;
			
		}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;

// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}

it works allright for turning towards the mouse, but it seems as if it’ll only turn while the mouse is held down and when pressing up (“W”) it goes towards the reticle… that’s not what i’m hoping for. before when i had the mouse clicking code and the movement code separate, it would turn and i could move but i’m having some difficulty intefrating them (i’m more than willing to separate them again if that would be more sane)

so, all i need to know how to do is to make the character turn towards the mouse when clicking and when NOT clicking, to return to it’s original orientation but turn in the direction you’re pressing on the WASD keys. (and the 3rd person controller that comes stock in the standard assets isn’t cutting it since if you push left… then right it is almost like the movement is not kicking in for a few seconds… and in an action game such as what i’m planning, that could mean a loss of life and unsatisfied players.)

EDIT:: reason i believe that integrating the two scripts into one is that i might need to pass some information along so that the two scripts don’t fight eachother for dominance and i can set up a proper condition for each state. if i’m going about this the wrong way by trying to do this, please let me know.

Second Edit::: okay… scratch that. i’m going to see about scrapping the mouse click method until i can figure out how to get the character to turn properly. thank you to those that helped though. i’ll post the code when i get it working or come up against a big issue that i cannot solve.

Okay… so, i’ve tried a few things and i’ve been able to narrow down what is needed.

first off, i’m going with two separate scripts like i have before which seems to work… somewhat.

for starters, here are the scripts that i’m using… one is on the root (to control the basic movement of WASD UP,Left,Right,Down)

//LIST OF THINGS TO DO
/*
1. create two conditional statements to read wether the mouse is or not clicked.
2. create mouseclick feature inside conditional statements
3. create orientation override in conditional statements
*/

var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 10.0;

private var moveDirection : Vector3 = Vector3.zero;

function Update() {
//grab the Character controller
var controller : CharacterController = GetComponent(CharacterController);


//test to see if Character is on the ground or not.
if (controller.isGrounded) {
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
debug = "vertical";



if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}

if (Input.GetMouseButton(0))
		{
			
		}

if (Input.GetMouseButton(0)==false)
		{
			
		}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;

// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}

i’ll get to that one later… for now i am trying to get the character to reorient itself when the mouse is NOT clicked.

here is the code for the mouse clicking which is the next up in the stack (the heirarchy i have so far is a controller at the base and the mesh added into that… mouseclick is added to the mesh, movement to the controller. that seems to separate things and keep the orientation of the controller OK.

here’s the mouseclick code.

// LookAtMouse will cause an object to rotate toward the cursor, along the y axis.
//
// To use, drop on an object that should always look toward the mouse cursor.
// Change the speed value to alter how quickly the object rotates toward the mouse.

var target : Transform;
var reticle1 : Transform;
var reticle2 : Transform;
var speed = 15.0;
var playerInitialOrientation;

//private var targetCache = Vector3(0,0,0);
//private var reticleCache = Vector3(0,0,0);

function Awake()
{
    myTransform = transform; //cache transform data for easy access/preformance
}

function Start()
{
    //print(reticle);
	
	
	var reticle1 = GameObject.FindWithTag("LMB").transform; //target the reticle
	var reticle2 = GameObject.FindWithTag("RMB").transform; //target the reticle
	var target = GameObject.FindWithTag("Player").transform; //target the player
	//print(reticle);
//	print(transform.x);
}
function Update () 
{
    // Generate a plane that intersects the transform's position with an upwards normal.
    var playerPlane = new Plane(Vector3.up, transform.position);
    var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
	var hitdist = 0.0;
    
	// If the ray is parallel to the plane, Raycast will return false.
    if (playerPlane.Raycast (ray, hitdist)) 
	{
        // Get the point along the ray that hits the calculated distance.
        var targetPoint = ray.GetPoint(hitdist);
		
		//reticleCache = targetPoint;
		targetCache = GameObject.FindWithTag("Player").transform;
		
		//print(reticleCache);
		//var isClickingLeft = false;
        // Determine the target rotation.  This is the rotation if the transform looks at the target point.
        var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
       
        // if Mouse click is held down, Smoothly rotate towards the target point.
        if (Input.GetMouseButton(0))
		{
			transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, speed * Time.deltaTime);
			reticle1.transform.position = targetPoint;
			//print(targetPoint);
		}
		if (Input.GetMouseButton(0)==false)
		{
			reticle1.transform.position = target.transform.position;
			//transform.rotation = Quaternion.Slerp(targetRotation, target.transform, speed * Time.deltaTime);
		}
		/*
		if (Input.GetMouseButton(1))
		{
			transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, speed * Time.deltaTime);
			reticle2.transform.position = targetPoint;
			//print(targetPoint);
		}
		if (Input.GetMouseButton(1)==false)
		{
			reticle2.transform.position = target.transform.position;
			transform.rotation = Quaternion.Slerp(targetRotation, transform.rotation, speed * Time.deltaTime);
		}
		*/
	}	
		
	

}

(i’ve knocked out the second reticle for now…)

now, i’ve tried adding into the mouse-up function the slerp feature to re-orient the mesh back to stock (to make it in line with the controller which is set to be in there as a variable/target/thingie) so that it is there to take any information i may need such as rotation.

but, when i put in the slerp function, it doesn’t go BACK to facing the right direction, it still thinks that it should be facing the mouse.

(once i can nail this one i will work on rotating the character as he moves… at worse, i can put in a whole whack of conditional statements such as “if W is pressed” “if W and A are pressed” “if W and D are pressed” etc…

any and all help, please… i’m not a good coder and this is starting to really cook my noodle.