However, it is done in 2.1 and I’m using 3.0. Although I’m a beginner I like trying to teach myself why certain errors are present. Unfortunately, I’m a little stumped on get_rot() in 3.0. I have discovered get_rotation() but it seems to be cumulative on key input as opposed to get_rot(), which appears to set a maximal value.
Thanks for your response. I implemented the code using ‘rotation’, however it rotates to a value of 0.5xxxx, when my desired value is 30 degrees. It is also still cumulative upon multiple presses of the input key.
First of all, 0.523599 radians == 30 degrees, so that’s not the problem.
The problem is you can’t just set the rotation (or position, etc.) of a RigidBody2D, because a rigid body is controlled by the physics engine. Because of this you might even see an instant during which your body snaps to 30 deg, but then immediately goes back to rotating based on its angular velocity.
You can’t control a physics body directly, you can only apply forces or impulses to it, and then the physics engine takes over.
Note: You should not change a RigidBody2D’s position or linear_velocity every frame or even very often. If you need to directly affect the body’s state, use _integrate_forces, which allows you to directly access the physics state.
I’ve not looked at the tutorial you’re referencing, but this is definitely not recommended use of RigidBody2D.
kidscancode | 2017-12-04 08:00
Okay, thanks again. I think I will have to dial it back and do some simpler tutorials to get a better understanding of fundamental mechanics.
There have been a number of changes between 2.1 and 3.0:
Member variables
You can access node properties directly:
# in 2.1
print(get_rot())
# in 3.0
print(rotation)
# in 2.1
set_rot(get_rot() + angle)
# in 3.0
rotation += angle
Orientation
In 3.0, setting rotation to 0 points to the right (along the positive x-axis), not upwards (along the negative y-axis) and a positive rotation is clockwise. This may be the source of your problem.
I’m not sure what you mean by “cumulative on key input” as rotation doesn’t have anything directly to do with input. Perhaps if you share the snippet of code you are using?
Thanks for taking the time to reply. My code snippet is in the comment to the reply above.
Icarus | 2017-12-04 07:44
Good day, so I have actually tried this tutorial just now and here is my code below. I think what he meant by cumulative, is the fact that if you keep on pressing space bar to to rotate the bird anti clockwise it will be set to -0.523599 but if you keep on pressing space bar further and print the rotation() you can clearly see that it keeps on subtracting until it goes positive the rads which means it has moved just more then 180 degrees. Then the bird goes from 30 degrees to 210 degrees. He finds it weird because in his code he did state that if the bird is rotated more then 30 degrees he should stay at 30 degrees and should keep on subtracting since its new rotation is set to -0.523599. I’m also wondering why it keeps on adding especially after you’ve set a limit to it.
Regarding the rotation being “cumulative”, are you possibly referring to the difference in rotate and set_rotation.
rotate(x)
# Will rotate object x radians relative to its CURRENT rotation
# versus
set_rotation(x)
# Will set its rotation relative to its ORIGINAL rotation
=== Solution ==
Okay so I actually took a look at the next part of the tutorial and to fix this actually you need to add set_angular_velocity(0), this will prevent it to go further.