This site requires JavaScript, please enable it in your browser!
Greenfoot back
johnguirgis
johnguirgis wrote ...

2018/1/16

Need Vector help!!!!

johnguirgis johnguirgis

2018/1/16

#
Is there a way I can set the length of a vector only in the horizontal direction. I'm making a game where I need to use vectors to move left, right, up, and down, but every time I need to set the length of a vector only in the horizontal direction, it also moves it up.
CxVercility CxVercility

2018/1/16

#
Ehhh. Can u provide some code? Hard to understand what you mean tbh
danpost danpost

2018/1/16

#
A vector has a direction and a length. If you need to ADD a horizontal vector to it, use the 'addVector' method (or whatever method there is that adds a vector force to the current vector. If you need to remove any currently set vertical force, then you would need to determine that part of the vector and subtract that force from the vector. Cannot provide any more details without knowing exactly what you are trying to do and without knowing what your Vector class is capable of (show the entire class code).
You need to login to post a reply.