Forum rules - please read before posting.

2.5D Movement Problem

i have problem on player movement with direct method
the problem is i have some rooms whit some cams on them and when player walk from one room to other and when camera switched then direction change instenly . i searche and found this and i think this is same as mine so i try to write that custom script but this is not working at all . so if iam going to right way then where is the problem ?

my code

* Adventure Creator
* by Chris Burton, 2013-2016
*
* "ActionTemplate.cs"
*
* This is a blank action template.
*
*/

using UnityEngine;
using System.Collections;

#if UNITY_EDITOR
using UnityEditor;
#endif

namespace AC
{

[System.Serializable]
public class cameraLockSnap : Action
{

// Declare variables here


public cameraLockSnap ()
{
this.isDisplayed = true;
category = ActionCategory.Custom;
title = "Lock Direction";
description = "this is to avoid the player moving in unwanted directions when the camera cuts.";
}


override public float Run ()
{
/*
* This function is called when the action is performed.
*
* The float to return is the time that the game
* should wait before moving on to the next action.
* Return 0f to make the action instantenous.
*
* For actions that take longer than one frame,
* you can return "defaultPauseTime" to make the game
* re-run this function a short time later. You can
* use the isRunning boolean to check if the action is
* being run for the first time, eg:
*/

if (!isRunning)
{
AC.KickStarter.playerInput.cameraLockSnap = true;
return defaultPauseTime;
}
else
{
isRunning = false;
return 0f;
}
}


#if UNITY_EDITOR

override public void ShowGUI ()
{
// Action-specific Inspector GUI code here

AfterRunningOption ();
}


public override string SetLabel ()
{
// Return a string used to describe the specific action's job.

string labelAdd = "";
return labelAdd;
}

#endif

}

}

Comments

  • As the commented words in the Run function say, you should return 0f if you are performing something that should occur instantly.  Try this instead:

    override public float Run ()
    {
      AC.KickStarter.playerInput.cameraLockSnap = true;
      return 0f;
    }
  • thanks chris
    i do what you say but still problem exist i use this custom action on the action list trigger that switched camera but still when player go from one room to other and when trigger switched cam the player movement direction changed
  • Does the movmenent change if you keep the input direction exactly the same, and does it only occur for certain cameras?  The more detail you can provide about the issue, the better we can help.

    The camera lock snap should automatically set itself to false if the input direction angle after a camera switch changes by more than 5 degrees.  Perhaps this is what's occuring - you can find out by opening PlayerInput.cs, and find the line:









    if
     (newMoveKeys.sqrMagnitude < 0.01f || Vector2.Angle (newMoveKeys, moveKeys) > 5f)



    If you change that "5f" to say "20f", does the problem go away?  It may be that you need to find the best value that suits you.
  • edited August 2016
    yes its happend when i keep direction exactly the same and its happend on all cams and i changed "5f" to lower and higher value but nothing changed and problem still exist . it can be because of player itself ?
    image
    image
     this is a small video from game scene that show the situation . this will happend whit WSAD to.
  • I don't know yet, but that shouldn't happen either way.  I will investigate this and will let you know if I need any more info to solve it, thanks for the alert.
  • Are you using Touch Screen for your input?  The current version disables the feature if you are, though I will enable it for v1.53a.
  • thanks chris and yes my input method is touch screen
    so can you tell me when that version comes out and it be safe (without any problem like broken projects and so on )to update when my game is almost done after 4 month of working ?
  • It's a simple change, you can make it yourself.  Open up MainCamera, and replace:

    if (KickStarter.stateHandler.gameState == GameState.Normal && KickStarter.settingsManager.movementMethod == MovementMethod.Direct && KickStarter.settingsManager.directMovementType == DirectMovementType.RelativeToCamera && KickStarter.settingsManager.inputMethod != InputMethod.TouchScreen && KickStarter.playerInput != null)

    with

    if (KickStarter.stateHandler.gameState == GameState.Normal && KickStarter.settingsManager.movementMethod == MovementMethod.Direct && KickStarter.settingsManager.directMovementType == DirectMovementType.RelativeToCamera && KickStarter.playerInput != null)
  • thanks chris for your good support it's worked !!!
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.