0
Answered

Player can't look and move at the same time

sl8rv 4 months ago in Game Creator updated by Marti (Lead Developer) 4 months ago 3

Getting started with GameCreator, just trying to get some of the basics working. Having trouble with a player and an FPS camera motor. The issue I'm running into is that while I've managed to get things working roughly my character can't change where they're looking while they're moving.

My set up is pretty simple, this is the hierarchy of the relevant aspects:
MainCamera

- Camera Controller

Player

- PlayerCamera

- FPS Camera Motor

I load the scene, add the player prefab, add the playercamera and set the Camera Controller motor to the FPS camera motor and I'm seeing this behavior. Code below:

IEnumerator loadScene(string name, LoadSceneMode mode){

AsyncOperation newScene = SceneManager.LoadSceneAsync(name, mode);

while (!newScene.isDone){ yield return null; }

SceneManager.SetActiveScene(SceneManager.GetSceneByName(name)); player = Instantiate( Resources.Load<GameObject>("Prefabs/Core/Player"),

new Vector3(500, 1, 500),

Quaternion.LookRotation(Vector3.forward, Vector3.up) // This should rotate forward );

GameObject playerCamera = Instantiate(

Resources.Load<GameObject>("Prefabs/Core/PlayerCamera"),

new Vector3(500, 2.5f, 500),

Quaternion.LookRotation(Vector3.forward, Vector3.up)

);


playerCamera.transform.parent = player.transform; mainCamera.GetComponent<CameraController>().currentCameraMotor = playerCamera.GetComponent<CameraMotor>(); }

Apologies for the poor formatting, but it doesn't appear that this forum has any code formatting tools. If anyone could point me to relevant documentation that would also be very helpful. I'm having a lot of trouble finding reasonable documentation for these components.

Unity version:
2019.4
Game Creator version:
1.1.9

Weird, i have the standard FPS Camera Motor in my setup as well, and have no problems. I'd try just deleting everything you have to player/character/camera related, and re-create them from the Game Creator toolbar.

I have other things in the project/scene... Unfortunately it's super common, just having GameCreator in my projects seems to break them pretty consistently.

I've opted to stop using GameCreator as there is no documentation for it, and creating even basic things risks destroying your game. Once I stopped using GameCreator this issue was trivial to resolve by just making an FPS camera from scratch.

Answered

Not sure why you're instantiating all things from code. Moreover, in the last line of code, you're setting the player as the parent of the camera motor. That makes little sense. Would you mind telling us what lead you to this? You can simply click onto the Player icon of the Game Creator Toolbar and it will create a player.

Also, for the camera, simply right click on the Hierarchy Panel and choose "Camera Motor" and select the "First Person Motor" option.

Another thing that might be wrong is your setup. All these components should not be inside of each other. So your hierarchy should look like this:


- Main Camera

- CameraMotor

- Player


Hope this helps