Player movement gun game tutorial

Hi having trouble with the player movement in the dream land shooter game tutorial on the unity website running 4.5 then updated to 4.6 on xp still. I’ve substituted spheres and then put all the code on top it all works well except the UI call not supported by the version. The problem tho is that when I try to move around with mouse the player doesn’t turn to the mouse and only shoots forward tho it does move position with the mouse. The forward is not getting turned? Idk if this is an xp problem says it was tested on 4.6 so started on 4.5 then reinstalled to 4.6 and can’t for the life of me figure out why it doesnt turn with the sample code. Am I misunderstanding and the animation is the part that is being turned?(I have no animations added left out the animator window part) Seems as tho it should still turn. The move() script works fine just the turning() that doesn’t do anything. I thought maybe was a change later on to the PlayerMovment script like some of the other scripts but haven’t found anything. As the video says should turn and move to the mouse just with that code but turn() just doesn’t work. I keep searching and all I find is different ways to make it work yet not that specific implementation. Has rigidbody has all the components just won’t turn. The EnemyAttack script will turn toward the player and move toward it. I’ve even tried making a child and explicit telling the child to turn (thinking that just have the sphere move and another turn for the shooting)but that fails as well. Is it win xp? I don’t know c# too well I understand the basics a bit can see the flow just doesn’t work like the tutorial said. Thought maybe the extra initial collider created by the sphere so removed that still no turn. In the edit>project settings> input on the first horizontal and vertical I had to change the drop down from: keyboard mouse button to mouse movement. Just to get the player to move with the mouse. Leads me to the thought I have to imply the mouse directly with the x and y input before the quaternion? Mouse.x mouse.y? I’m really stumped at a point to start over just to figure this out. That could be starting on 4.5 version could affect it. Could child prefab cause not to turn? I can’t find anything locking it. Have the constraints to lock to the plane on and off still no turn() numbers don’t change tho the movement numbers do change and move the player. Could the collider axis matter? I’m really just spit balling cause all new to me with tiny bit of coding background. It’s similar to me by means of website java and playing muds set up whole life bars and all that with zmud if know Muds, Im an advanced c4d user. So have lil bit of the basics. But I’m totally confused. Basically taking my c4d and using the sphere to do all the coding then drop the c4d as a child to ride around. Figuring the less poly of the sphere will run better just like dynamics in c4d? Really unlocking a door for me. Just can’t get this simple turning() to work with mouse position exactly copied from the tutorial onto the sphere. Could the c4d object made prefab be locking it somehow? When I switch the project settings input to keyboard/ mouse button it acts the same movement works with buttons turning doesn’t. I thought making the c4d child like a turret just grab it secondary to make it work yet taking the pieces out of player movement and creating a new script still doesn’t allow it to turn. Or is this all that only works in pro version?

Thanks at all sorry if this question /thread placed wrongly. Trying to learn this while wait for a real computer to better know the program/coding in its infancy. I see I could just load the preprogrammed controls but I want to learn.

Awesome platform very simple to implement n transfer my own 3D amazed I had had not found it earlier just this lil problem.

I didvthe rolling ball tutorial worked perfect and tried to implement turning on there after was all set up and still could not figure how to get it to turn with the horizontal and vertical input.

Whoa… holy wall of text, Batman!

Perhaps try again, using shorter sentences and more punctuation. Try to be really clear about what you’re trying to do, and what’s preventing you from doing that.

Thanks for the reply

Yeah I babble cause I see so much in everything lol…Dreamland shooter tutorial turn() doesn’t seem to work on win xp unity ver4.6. Did everything in the videos and copy pasted the code. PlayerMovment script Move() works turn() doesn’t.
I skipped the animation part, does the turn() turn the animation and not the actual player object?

I started in unity ver 4.5 then upgraded to 4.6 would that matter?

Also placed code on sphere (reason why no animations) more reason wondering if needs animations to turn?

Many other for instances above in my babble yet main point will not turn() with tutorial scripts and video info on a simple sphere.

Rest works well.

OK, those are good questions. Most tutorials have a forum thread that goes with them. I would suggest you look for that, and post those questions there.

But most likely, it’s something in the part you skipped. Go back and do that part too, and it will probably work.

No. 4.6 is a minor update to 4.5; I wouldn’t expect that to matter.

Maybe. I haven’t done that tutorial, so I don’t know how turning works there. But generally, if I’m doing a tutorial and I skip or change some things, and then stuff doesn’t work as expected, it’s probably because of the stuff I skipped or changed.

Cool thanks again. Seemed simple enough. Guess its tied in somehow even if quoted out. Going to find the specific forum

using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
public float speed = 6f; // The speed that the player will move at.

Vector3 movement; // The vector to store the direction of the player’s movement.
//Animator anim; // Reference to the animator component.
Rigidbody playerRigidbody; // Reference to the player’s rigidbody.
int floorMask; // A layer mask so that a ray can be cast just at gameobjects on the floor layer.
float camRayLength = 100f; // The length of the ray from the camera into the scene.

void Awake ()
{
// Create a layer mask for the floor layer.
floorMask = LayerMask.GetMask (“Floor”);

// Set up references.
// anim = GetComponent ();
playerRigidbody = GetComponent ();
}

void FixedUpdate ()
{
// Store the input axes.
float h = Input.GetAxisRaw (“Horizontal”);
float v = Input.GetAxisRaw (“Vertical”);

// Move the player around the scene.
Move (h, v);

// Turn the player to face the mouse cursor.
Turning (h, v);

// Animate the player.
// Animating (h, v);
}

void Move (float h, float v)
{
// Set the movement vector based on the axis input.
movement.Set (h, 0f, v);

// Normalise the movement vector and make it proportional to the speed per second.
movement = movement.normalized * speed * Time.deltaTime;

// Move the player to it’s current position plus the movement.
playerRigidbody.MovePosition (transform.position + movement);
}

void Turning ()
{
// Create a ray from the mouse cursor on screen in the direction of the camera.
Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);

// Create a RaycastHit variable to store information about what was hit by the ray.
RaycastHit floorHit;

// Perform the raycast and if it hits something on the floor layer…
if(Physics.Raycast (camRay, out floorHit, camRayLength, floorMask))
{
// Create a vector from the player to the point on the floor the raycast from the mouse hit.
Vector3 playerToMouse = floorHit.point - transform.position;

// Ensure the vector is entirely along the floor plane.
playerToMouse.y = 0f;

// Create a quaternion (rotation) based on looking down the vector from the player to the mouse.
Quaternion newRotation = Quaternion.LookRotation (playerToMouse);

// Set the player’s rotation to this new rotation.
playerRigidbody.MoveRotation (newRotation);
}
}

// void Animating (float h, float v)
//{
// Create a boolean that is true if either of the input axes is non-zero.
// bool walking = h != 0f || v != 0f;

// Tell the animator whether or not the player is walking.
//anim.SetBool (“IsWalking”, walking);
//}
}

Feel stupid never added floor to floor layer lmao live n learn thanks again

Cool, glad you figured it out!

(But hey, in the future, please use code tags for your code — they make it much more readable!)