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

2019/4/10

does move() only move the actor in angles that are multiples of 45

TheGoldenProof TheGoldenProof

2019/4/10

#
In the game I'm making I have a thing which is supposed to shoot every half second (30 cycles). The bullets are created with an angle and then they move forward at a speed of 1. the problem is, no matter what angle i make them at, it will only move in the closest multiple of 45 degrees. is move(1) limited to only move in the 8 pixels around the object? if so, how could I make it move at any angle at speed 1?
ErasedBlade ErasedBlade

2019/4/10

#
Ok 1st of all the move method only moves left and right, so that’s not the issue here. What the issue I would say is the angle it’s set up as. If you use a turn method before the move it should work example
Public void turn()
{
turn(90);
move(1);
}
I used the 1 value for the speed since that’s what you put in the original post and 90 because its widely used If you want it to be used with multiple angles I would try this
turn(angles);
And in the constrctor
Private int angles
public Object(int angle)
{
angles =angle;
}
TheGoldenProof TheGoldenProof

2019/4/10

#
Actor.turn(x) is the same thing as setRotation(getRotation()+x), also, I don't want to bullets to be turning, I just want to spawn them and have them go in any direction outward from their spawn, but they only go 8 directions: up, up-left, left, down-left, down, down-right, right, or up-right, the multiples of 45 degrees. If i used turn(90), it would be even more limiting, giving me only 4 possible directions to go. I want to be able to go 360 different directions. also, I don't know what you mean by only moves left and right. It only moves in the direction its facing (or backwards), which by default is left (or right).
ErasedBlade ErasedBlade

2019/4/10

#
Sorry I’m new to programming I only recently started so I might not fully be able to understand quite yet, however do you have a method to spawn them in, and if so can you post it for me?
TheGoldenProof TheGoldenProof

2019/4/10

#
public void act() {
   setRotation(rotation);
   move(1);
}
no matter what rotation it is, it only moves in the closest multiple of 45 degrees. This isn't my exact code because i have other things going on in my act method but this is the only part that has to do with the objects movement and rotation (or anything else relevant).
ErasedBlade ErasedBlade

2019/4/10

#
Heres what I was thinking. Put the setRotation in the method that spawns in the bullets, so it would only turn once it spawns in. And also check if you don’t have any variables called rotation in your other subclasses. The same thing happened to me, however in my case I have it set to a spacific value in my other class and that transferred over.
TheGoldenProof TheGoldenProof

2019/4/10

#
I originally had setRotation in the constructor, which is what you were saying, but it should make any difference (except performance). i dont have any other variables or subclasses that should interfere.
ErasedBlade ErasedBlade

2019/4/10

#
Huh well I’m not sure then what could be causing it to only move every 45 degrees then? I’m I’m sorry I thought I could be of some help
Super_Hippo Super_Hippo

2019/4/10

#
An actor is always in the middle of a cell. If you move one step, you have eight possible directions. To fix this issue, you have to save the exact position, not only the middle of the cell (which is what getX and getY are returning). The easiest way to do this is to import the SmoothMover class and have all classes which needs exact moving extend this class.
TheGoldenProof TheGoldenProof

2019/4/10

#
Thank you so much! I was about to totally lose it. I forgot that that class existed. It all works great now!
You need to login to post a reply.