• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Durakken

Unity3d movement reverses

7 posts in this topic

The basic problem is that pressing forward, the player object moves forward until I rotate and then it starts moving in a different direction relative to the camera...

 

After I started typing this I realized that the character was rotating, but the camera wasn't keeping to the back of the character.

 

But that comes with a new problem... I don't know how to rotate the camera the way I want to. It has to rotate around an offset center based on the character.

 

Can someone tell me what how to do that so that it corrects this problem?

 

Here's the movement script, input is handled in another

And followed by what I currently have for the camera.

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {
	float WalkSpeed = 3.0f;
	float RunSpeed = 6.0f;
	float TurnSpeed = 3.0f;

	void Update() {
		CharacterController Move = GetComponent<CharacterController>();
		GetInput controller = gameObject.GetComponent<GetInput>();

		//transform.Rotate(0, controller.Turn * TurnSpeed, 0);
		Vector3 move = new Vector3(controller.Strafe, 0, controller.Forward);

		float Speed = WalkSpeed;
		Move.SimpleMove(move * Speed);
	}
}
using UnityEngine;
using System.Collections;

public class CameraMovement : MonoBehaviour {
	float TurnSpeed = 3.0f;

	// Update is called once per frame
	void Update () {
		GetInput controller = GameObject.Find("Player").GetComponent<GetInput>();

		transform.Rotate(0, controller.Turn * TurnSpeed, 0);
	}
}
0

Share this post


Link to post
Share on other sites

For the movement, you probably want it in FixedUpdate rather than Update, otherwise you are going to get some weird skipping going on.

 

You probably want something along these lines, although there are certainly many, many, many other ways of doing it.

function FixedUpdate() {
	if(!isControllable)
		Input.ResetInputAxes();	
	else{
		if (grounded) {
			moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
			moveDirection = transform.TransformDirection(moveDirection);
			moveDirection *= rollSpeed;
			
			//Find rotation based upon axes if need to turn
			moveHorz = Input.GetAxis("Horizontal");
			if (moveHorz > 0) // right
				rotateDirection = new Vector3(0, 1, 0);
			else if (moveHorz < 0) //left
				rotateDirection = new Vector3(0, -1, 0);
			else // not turning
				rotateDirection = new Vector3 (0, 0, 0);
							
			//Jump Controls
			if (Input.GetButton ("Jump")) {
				moveDirection.y = jumpSpeed;
			}			
	... assorted specialized controls here ....
	
		// Apply gravity to end Jump, enable falling, and make sure he's touching the ground
		moveDirection.y -= gravity * Time.deltaTime; 
		
		// Move and rotate the controller
		var flags = controller.Move(moveDirection * Time.deltaTime);  
		controller.transform.Rotate(rotateDirection * Time.deltaTime, rotateSpeed);
		grounded = ((flags & CollisionFlags.CollidedBelow) != 0 );
	}
} 

As for the follow camera, there are even more ways to do that then there are player controls.

1

Share this post


Link to post
Share on other sites

I think you might have misunderstood my problem... It's not that I couldn't "rotate" It's that I can't revolve.

 

I don't want to draw it out  so just imagine that i'm describing a fixed directional space...

 

When I'm facing forward and my camera is facing forward everything is fine.

 

The problem is that when I rotate the character, the character is facing say, left or right, but the camera is still facing forward OR if I rotate the camera, the camera it's facing the same direction BUT it's now parallel to the character's facing direction, but it is still in its same position relative to the character...

 

So if my character is facing forward my position should be (0, 1, -5), but when I'm facing "backward" it should be (0, 1, 5), pointing at the character, but instead it is still at (0, 1, -5) pointing away, because the camera isn't revolving with the rotation... I don't know how to calculate that revolution.

 

Thank you for the above script, but I don't need any of that... at least I don't think I do >.>

 

 

I continued to search after I posted and found nothing that I could use that I understood... but I'll continue searching.

0

Share this post


Link to post
Share on other sites

- Make sure your character model pivot is correct so the Z axis is on the front of the char.

- Rotate him only on the Y axis, move him forward only on the Z axis. 

- This dude converted the built in scripts for cameras do C#: 

http://psychicparrotgames.com/blog/2013/06/06/unity-third-person-controller-and-third-person-camera-scripts-converted-to-c/

 

You should check the scripts out and tweek it how you like it.

But personaly I think the public parameters that they provide are usualy enough to achieve what I want most of the time.

 

 

Hope that helps.

Edited by brunopava
0

Share this post


Link to post
Share on other sites

Have that already. Didn't help ^.^

I feel stupid though... I described what was happening wrongly... and I don't know why it's happening.

It appears the camera is revolving but the character isn't...which is odd cuz the script is on the character.

 

I've tried just putting those scripts on the character/camera and they don't do the thing i want for some reason and so even if I modify them or pick the stuff out of them that I think works, it's just a random guess. And worse is that It appears it is the code that makes it work is in multiple parts so even if I guess right about the code that makes it work, it still won't work, cuz it's not complete. 

0

Share this post


Link to post
Share on other sites


I feel stupid though... I described what was happening wrongly... and I don't know why it's happening.

I think every experienced programmer has gone through that. It is tough.  Not just difficult as far as development, but also can make you doubt your skills.

 

One option is to visit the Unity forums and store and look over the many existing scripts out there that do the job. You don't get the experience of doing it, but you would have something that works.

 

So let's assume you want to write your own.

 

First, I recommend you take a short break and get some emotional distance if possible.

 

Then, disconnect the affected components. If you have source control keep your old version around, otherwise archive the old version in a safe place.

 

Then, start over. Take things one small step at a time.

 

Start out by carefully writing down your goals and requirements. Write down the desired result, not the math.

 

Since it is a camera, I'd start with a simple scripted object that follows a track. This is your character you want to watch. You can even attach a default character controller making them move with WASD or whatever, just make something that moves.

 

Then put an empty follow-cam script. Don't attach it to a camera.  Attach it to a small cube.  Start with the empty MonoBehavior and a FixedUpdate, and attach it to the small cube.  Run, it should do nothing. 

 

Then, very slowly, feature by feature, add a piece at a time to make the small cube follow the character in a nice smooth way that meets your needs. Maybe you want to go physics based for the motion of the camera and use LookAt to orient it correctly, or maybe you have some other way you want it to work.

 

Take things in small steps. Save out a copy (preferably with version control) every time you get a step. If something doesn't work right you can back up a step to the previously saved file and try again.

 

 

When you aren't sure what is wrong and you aren't sure how to describe it, just take a deep breath, clean everything out, and methodically follow the established processes for software development.  And when you really get deeply stuck, you can solve almost any problem by adding an abstraction, then filling in the abstraction's details later.

0

Share this post


Link to post
Share on other sites

I just set it aside, because it isn't quite important to what I wanted to figure out how to do which...

 

Place a char capsule

Place a trigger 

move the capsule to the trigger

Freeze character movement + Trigger a battle menu

Be able to scroll through the options from that menu

 

Next step is to construct the basic elements for random battles

 

On another note...

Every time I come back here and look at this post I get a new idea as to why something might be going wrong hehe

 

Ok, what I think what might be going on is that for some reason the character is moving along the world x and y coordinates rather than using the internal rotation, but I'm not sure... Dunno why that would be the case though. I'm pretty sure this has a lot more to do with my lack of familiarity with coding as I haven't done a lot of it recently and little unity C# overall.

 

edit: Could it be something to do with this line from your script code?

moveDirection = transform.TransformDirection(moveDirection);

/end edit

 

The reason I want to program it myself is so I know exactly what it is doing so I can edit thing where I need to.

Edited by Durakken
0

Share this post


Link to post
Share on other sites

Well turns out that my last guess was right...

 

Here's the super simple script that allows forward/backward/left/right/horizontal camera rotation... no jumping is in the game so no "grounded" is needed.

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {
	float WalkSpeed = 3.0f;
	float RunSpeed = 6.0f;
	float TurnSpeed = 3.0f;
	float Speed;

	void Update() {
		CharacterController Move = GetComponent<CharacterController>();
		GetInput controller = gameObject.GetComponent<GetInput>();
		WorldStatus WorldStatus = GameObject.Find("Player").GetComponent<WorldStatus>();

		if(WorldStatus.mode == "awake") {
			transform.Rotate(0, controller.Turn * TurnSpeed, 0);
			Vector3 move = transform.TransformDirection(new Vector3(controller.Strafe, 0, controller.Forward));

			if(controller.Run == 1) {
				Speed = RunSpeed;
			} else {
				Speed = WalkSpeed;
			}
			Move.SimpleMove(move * Speed);
		}
	}
}

Question... Do you guys know if it would be possible to get rid of the call for character controller since it is in GetInput...

 

Also also I have a button repeat timer thingy to slow down input so that it doesn't go instantly to the next option... what's a good way to do this or a good number?

 

My testing out script is like this....

void Update() {
	if(myTimer > 0){
		myTimer -= Time.deltaTime;
	} else {
		if up/down go to next position

		myTimer = 5f * Time.deltaTime;
	}
}

It works... but not quite nicely. Sometimes it goes too fast and other times too slow... 

Edited by Durakken
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0