Forum rules - please read before posting.

how to restrict player movement to X axis in 3D game?

edited April 2018 in Technical Q&A
Hi,
I am new to AC, but  have worked with Unity for some time - and I did watch the tutorial videos and read the manual monster.

I want to create a 2D sprite player that moves in a side scrolling 3D scene.
Which just means: constrict player movement to the X axis, while the camera follows.
However, I just cannot get the player character to move at all!

I am using a 2D (2DTK ) animated sprite for the character, child to a 3D character GO, created by the  "Character Wizard" and set AC to "direct movement / keyboard or controller".

The capsule collider on the player GO works fine with the floor and wall box colliders.
But there are 3 issues:

1. in most cases either the character moves ONLY on the Z axis, and ignores all other input, and then bounces or jitters off the wall collider.

2. or it moves Z and X, but not in straight lines, but along some curved path. meaning, just going +X and then -X offsets the entire character on the Z axis, cos it apparently wants to "curve back"along a bezier path.

3. "jumping" doesn't seem to work at all with this setup.

I have tried every check box option there is to no avail (mostly the whole character either doesn't move at all, or will just move along the Z axis, regardless of input). (Tank controls just freeze the whole character, retro style movement, ignore gravity and "move with rigidbody" "off" seem to partially work).

So my questions are:
How can i just plain disable all Z axis movement?
How can I disable the forced bezier path movement - since my game is more of a classic linear movement thing?
Is there any way of having the character (incl it's collider) being able to jump? or does this need to be faked with sprite animations?

Since I used 2 full days on this to no avail, all help is much appreciated ! :-)

NB: unity 5.6.1, latest version of AC and 2Dtk

Comments

  • Welcome to the community, @fettklump.

    As this is a very visual problem, it may help to see some screenshots that illustrate your scene setup and what exactly is occuring.  If you wish for the player to move along the X-axis, and the camera is facing down the Z-axis, then you only want Horizontal input to have an effect, correct?

    What input are you pressing when the character moves along the Z-axis (presumably this is towards/away from the camera)?  The Player: Constrain Action can be used to prevent vertical (depth) input from having an effect.

    If the direction of travel does not seem to correlate to the direction of input (ie. pressing the right-arrow makes him move "up"), check that AC's MainCamera is in the correct position.  If you are using a custom camera, you will need to follow the steps outlined in the "Custom cameras" chapter of the Manual to ensure the AC MainCamera follows it.

    I'm guessing that the "bezier" behaviour you're describing is due to the fact that the player is turning while changing direction.  One way to prevent this is to set their Turn speed property to a negative value, so that turning is instantaneous.

    Alternatively the following script, when attached to your Player's root object, will snap movement in the Z-axis to a given value (but still allow for gradual turning animations)

    http://pasteall.org/929729/csharp

    A character should be able to jump so long as they have a Rigidbody component on their root, and that their own colliders are not placed on the same layers defined in your Ground-check layer(s) field in his Inspector.  Is this the case?
  • Hi!
    thank you for your reply!!

    Yes, the camera is facing down the Z axis and I only need horizontal input. I haven't done anything with the default camera setting, as I am still struggling with movement input.

    When only the Z movement would work, I pressed the "D" key, or "->" right arrow. Yet it would just move along the Z axis. I also found out that the capsule collider on the Player root GO would spin around its Y axis, perpetually. (I do think the minus value on the turning speed may have fixed all this)

    - The "jumping" works at random now all of a sudden. I found out that the "ground-check" in the player GO physics settings defaults itself to "Nothing" at random. This also seems to be the reason for occasional "jumping works: but can infinite jump-fly into the sky", which I have read about on this forum.

    - The "player: constrain" action  works! :D
    However: I only could get it to work when it's in the "ActionList_On_Start_Game" - which sounded logical. However, this action list is per default hooked up to the "Cutscene settings".  I guess this is the wrong place? (the action didn't work when attached to the player GO).
    If so: Where do I place this action instead?

    - another question regarding jumping: can the jump and fall speed/duration be adjusted? I read a reply on this forum for fiddling with Player rigidbody "mass", and "jump speed" in the movement settings. This only seemed to affect the height of jumping, not the actual duration. There also seems to be a slight lag between input (space bar press) and actual Player Go jump. 

    Thank's again for the support! much much appreciated ! :-)

    (PS: working on finding hosting space for screenshots for better information)



  • Hi,
    I cannot say much about the first two issues without knowing exactly how you set things up (not enough experience yet ;) )

    I prefer using OnStart Actionlists for every single scene to make sure the player sticks to his rails. Sometimes things need to be adjusted within a scene. And dont worry about the word cutscenes. It is the right place.

    RigidBody jumping is based on a kind of physics simulation. Just as in real life, jumping is not based on a fix time, but on gravity acceleration, mass of the object and its initial speed/force (I think that is what jump speed changes). Not sure if that is true, but it is how I explained the behavior to myself xD

    Btw: I also use the sidescrolling 2D player in a 3D world with direct control setup. Get in touch if you want, maybe we can share some knowledge.


  • - Characters are intended to rotate in 3D space, regardless of their graphics type.  This is the reason for 2D characters to be placed in a child object - they'll be counter-rotated every frame to face the camera.  You can prevent this, however, by unchecking Turn root object in 3D space?.

    - The "flying" effect can occur if Ignore gravity? is checked in the Player Inspector.  Are you able to pin down when the Ground-check layer(s) field resets to Nothing?

    - Actions and ActionLists won't trigger by themselves - so a component attached to the Player object is not going to run unless told.  Initialising a scene is best done in your OnStart Cutscene, which you can define/assign in the Scene Manager.  As @Klebautermann rightly points out, the name "Cutscene" is just a container for Actions - setting its When running field to Run In Background will not cause it to interrupt or pause gameplay.  Player constraints are also a per-scene property, so it's best to run that Action in your scene anyway.

    - You could try adjusting the Gravity vector in Unity's Physics settings, but the properties you mentioned are the only ones AC accounts for in calculations.  It should be noted that the jumping mechanic is rather basic - if you're looking for more refined direct motion control, it may be worth relying on a separate controller asset.  AC can be integrated with motion controllers quite easily - see the Manual's "Custom motion controllers" chapter, and a fair few integration scripts can also be found on the AC wiki: http://adventure-creator.wikia.com/wiki/Category:Integrations
  • thanks for all your replies!
    Unfortunately, after 4 days of trying to get this to work I realized I am trying to make a game that AC probably is not meant to facilitate. So I am throwing the towel for now - and go back to Playmaker.

    I'll come back and dig into AC again for my next game project, which will be a point and click adventure and not a button mashing platformer, like the one I am working on now.

    I'll be back
    :smile:

  • edited April 2018
    No problem, @fettklump - it is important to use the right tool for the job.

    For completeness, however, it is certainly possible to rely on Playmaker to control the player.  A sample integration script can be found on the wiki here: http://adventure-creator.wikia.com/wiki/Using_PlayMaker_to_control_the_Player
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.