- Home /
When I move my arms back and forth, the player stops falling or moves upward
So while I play my game, a 2D sidescroller, and I jump and move the arms from side to side, my player stops falling for a brief moment, or he goes up a bit. So I could in fact manage to fly in my game due to this bug. I would like this to be fixed. The arms have no colliders, only the body does. I use a character Controller, and if you need any code, be free to ask. If you don't quite get what I mean, here's a 30 second youtube video of my program so far can be found here . Thank you for all your help.
Bonus Question: I use "D" to move forward, and "A" to move back when my character is facing forward (nose is facing right). When my character changes direct (his nose faces left), D still moves it forward, and A moves it backward, but I want to switch the valuse. So if character is facing left, A is to go forward, and D is to go backwards. I hope that makes sense. But this a bonus question, so if you know a solution great, if not, please try to focus on the main problem. Thank you very much for your time.
Can you show your actual code? Its hard to see what the problem is without a snippet of the code. $$anonymous$$y guess would be that when you flip your character horizontally, you're not doing it in an efficient way.
The code you requested for me flipping my character around is this:
if(hitPoint.x > transform.position.x) // hitPoint is mouse position { forward = true; }
if(hitPoint.x < transform.position.x)
{
forward = false;
}
if(forward) //forward is true, I face right (forward in game world) { transform.eulerAngles = Vector3(0,0,0); }
if(!forward) // forward is false, I face left (backward in game world) { transform.eulerAngles = Vector3(0,180,0); }
Can you post up some more code? I am wondering if it has something to do with the movement code and not really the rotation. Also, are the other rotations drifting at all or do they stay at 0?
Here, try two things. The bug is probably happening when hitPoint.x is equal to transform.position.x. So an easy fix would be change one of the equations(lets use the second) to
hitPoint.x <= transform.position.x
Alternatively, if that doesn't work, there could be a weird bug with your eulerAngles thing. So ins$$anonymous$$d of
transform.eulerAngles = Vector3(0,180,0);
use
transform.eulerAngles.y = 180;
Good luck on the project!
Answer by whydoidoit · Jun 15, 2012 at 11:56 PM
You need to remove this I think:
moveDirection = transform.TransformDirection(moveDirection); //remove
Because that is changing your left right movement depending on the rotation of the character.
I have to say I love the title of this post - but it does make think you've wired yourself up to some strange mechanism to control your game.
That worked, thank you very much. Also my apologies if the title was misleading or confusing. I also can assure you, it's a simple game with simple mechanics... So far.
Answer by TahirG · Jun 13, 2012 at 11:05 PM
Its not your "arms". Your "arms" are only looking towards the target. How do you handle jumping? Did you make sure the character ca only jump if he's on the ground? You should be able to say something like:
if (Grounded & Input.GetButtonDown("Jump"))
// jump code here ......
$$anonymous$$y character can only jump when he's on the ground. In the video, I'm not moving up because I am hitting the jump button, it's because I'm turning, and when I do, I get that bug. Here's my turning around code:
if(hitPoint.x > transform.position.x) // hitPoint is mouse position { forward = true; }
if(hitPoint.x < transform.position.x)
{
forward = false;
}
if(forward) //forward is true, I face right (forward in game world) { transform.eulerAngles = Vector3(0,0,0); }
if(!forward) // forward is false, I face left (backward in game world) { transform.eulerAngles = Vector3(0,180,0); }