hi,
i am trying to edit the animation so when the user click's the 'fire1' button it move the chracter controller in the direction the mouse is pointing. i have got the user to move when they press the mouse button but it will only go in one direction. Here my script if you can help thank you:
The reason your character is always moving in the same direction is that you are always moving your character controller along its forward vector. To make the character move in the direction of the mouse, you would first need to calculate the "position" of the mouse in the game world and then calculate the angle between the character's current heading, and then rotate the character by that amount (or use Transform.LookAt if you don't care about a smooth rotation). To get the position of the mouse in your world, well, that depends a lot on what your game world is like. Should the mouse click's position be the top-most object under the mouse? Only the ground? Some combination? Without knowing more I can only offer a possible solution:
During the update of one of your game objects check to see if the mouse is clicked. If so, shoot a ray into the scene and set the layer mask so that you only collide with a certain layer that contains everything you want to be clickable for the purposes of your character's movement. You can shoot a ray into the scene using:
int layer = 1 << LayerMask.NameToLayer("name of your collision layer");
RaycastHit hitInfo = new RaycastHit();
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hitInfo, Mathf.Infinity, layer)) {
// use hitInfo here to determine where the clicked point
// was and orient your character towards it
}
Again, it's a fairly complex thing you're asking about but hopefully this is at least a start for you.