2D : How to overwrite rigidbody velocity when "skill" input pressed ???
Hi guys, I'm having a hard time figure it out. I'm moving my character by setting is rigidbody.velocity like this :
void Update () {
var right = inputState.GetButtonValue (inputButtons [0]);
var left = inputState.GetButtonValue (inputButtons [1]);
if ((right || left)&& !esquive) {
var tmpSpeed = speed;
var VelX = tmpSpeed * (float)inputState.direction;
body2d.velocity = new Vector2 (VelX, body2d.velocity.y);
}
Now, this is all fine but when I try to change it with magic or skill uses, understand when another behavior script is triggered, there seem to have a conflict between the different body.velocity requests and my player just keep on walking...
For instance a simple "forward dash" like
void OnEnable()
{
body = GetComponentInParent<Rigidbody2D> ();
body.velocity = new Vector2 (500, 20);
}
only works if i'm not trying to walk at the same time... I don't know how to easily fix it, I'm thinking about toggling the inputmanager during the dash but it seems so overworked ^^ Any help would be really appreciated :)
Are you saying you use a separate script for each movement function? I wouldn't say this is advisable.
The first one is for simple movement (walking as usual) and I'm working on a "skill system" : when player gets a new skill, the skill gameobject become a child of player, and by enabling it (with the skill key), the behavior is triggered. it's working great for a lot of stuff so far, I don't really see why the skill couldn't be on a separate script.
And this happens everytime you activate a skill? Sounds like a lot of work for you and the program.
Personally I'd believe that the overuse of OnEnable will eventually result in something going wrong.
I'm trying to see where in the script the behaviours become 'overridden'. You may set the velocity separately but wont the value simply revert on every update?