- Home /
Movement vector does not take the gravity vector..
I am trying to make a game where the gravity can switch in some areas.
I use two vectors for this: GravityDown wich drags the player down and GravityRight wich indicates in wich direction the player will run.
If i change this vectors, they will be changed in the inspector but the code will take the old values.
It will also not run if i create new vectors..
Code:
var GravityDown : Vector3 = new Vector3(0,-1,0);
var GravityRight: Vector3=new Vector3(0,0,1);
function Update()
{
// change local gravity
if(Input.GetButton("Fire2")
{
GravityDown=new Vector3(0,0,1); // gravity drags to the right
GravityRight=new Vector3(0,1,0); // player runs up, down
}
forwardMovement = GravityRight*(Right-Left) * Time.deltaTime * MovementSpeed;
print("GravityRight:"+GravityRight.x+GravityRight.y+GravityRight.z);
forwardMovement+=GravityDown*airMultiplier;
transform.position+=forwardMovement;
}
it will show the right variables in the print but it will drag the player on the same way ever...
what can i do here?
print("GravityRight:" + GravityRight); should be enough. It's nicer formatted.
Answer by Bunny83 · May 26, 2011 at 10:15 AM
If you press Fire2 you set the "GravityRight" vector to point to the right (World space). What change do you expect? where do you change the vector? And most important what is "Right" and "Left". Is it a 3D game? I just wonder why you move the right(x-axis)?
edit
Just saw you don't use "right(x-axis)" you use forward (z-axis). Why do you call it right?
Answer by ben0bi · May 26, 2011 at 10:39 AM
The change wich i would expect is that the player moves to the right by gravity, but all he does is moving to the ground like before. If fire2 was pressed, the player should move up and down and gravity should drag towards right. Before fire2 is pressed, gravity drags down and the player moves right/left.
its a 2d sidescroller jumpnrun.
i removed rigidbody/collisionbox/charactercontroller to make it move without physics and stuff.
I also removed all "real physics" gravity stuff..
Right and Left can be 1 or 0 each, so Right-Left can be between -1 and 1
all the stuff is in the players update function
answer to the edit: the game level is aligned on the z axis and its 2d sidescrolling so right and left are z+ and z- from camera view point.
You should edit your question ins$$anonymous$$d of posting an answer ;) or use comments.
I don't see any problem with that script. As long as GravityRight (which should be called something like movementDirection) is changed it should work. Are you sure you don't reset it somewhere else? $$anonymous$$aybe from another script? You can print the forward$$anonymous$$ovement variable to see if it's right.