i need help in understanding rotation values in webots. How do I calculate and set them?
I want my robot to rotate in direction of the certain object.
For example, if the ball is rolling around the robot, the robot tries to get the position of the ball and rotate to it, so that the robot is always facing the ball.
Does anybody have an idea how can I do it?
My thoughts on coding it:
Get position of the ball
Get position of the robot
Calculate the angle between them
Rotate the robot by calculated angle
Thanks in advance!
You don't have to calculate the angle, it is enough to find the position of the ball in a 2D image plane. If the ball is left from the image center the robot should rotate left and if the ball is right from the image center the robot should rotate right.
You can find an example here:
https://github.com/lukicdarkoo/webots-example-visual-tracking
and you can see the result here:
https://lukicdarkoo.github.io/webots-example-visual-tracking/
Related
I am thinking about the simplest way of rotating an object in coordination system which looks like this:
0
-90 90
-180/180
I need to rotate an object until it reaches a given angle. It has to support rotation in both directions. I receive information about the object's current rotation. I have to create a while loop condition when it should stop rotating. It cannot be simple equality statement as the information I receive is not that precise.
EDIT:
The object is a drone which sends me data about its current rotation along z-axis. I rotate it by sending a request to rotate in a given direction. Based on information about its current rotation and the angle by which I want him to rotate (plus the direction of rotation), I need to set up a condition when it should stop rotating and send an apropriate requst.
Theoretically, you would need to have another variable that took the direction of rotation (clockwise or anti-clockwise). If the direction was clockwise, you would have angles assigned 0, 90, 180, 270 in clockwise direction. Same for anticlockwise.
Your while loop would be for angle < given angle, since with the variables being assigned values based on the direction of rotation you wouldn't have to worry about +/- values for the angles.
This is probably a really basic answer and not what you were hoping for, but I hope it helped a little!
I am trying to create a simple scene in 3d (in python) where you have a cube in front of you, and you are able to rotate it around with the mouse.
I understand that you should rotate the complete scene to mimic camera movement but i can't figure out how you should do this.
Just to clarify I want the camera (or scene) to move a bit like blender (the program).
Thanks in advance
Ok I think i have found what you should do
just for the people that have trouble with this like I did this is the way you should do it:
to rotate around a cube with the camera in opengl:
your x mouse value has to be added to the z rotator of your scene
and the cosinus of your y mouse value has to be added to the x rotator
and then the sinus of your y mouse value has to be subtracted of your y rotator
that should do it
I recently just asked this question. I got my answer the only problem is the rotation is weird. It does not have one center point. The best way I can describe the rotation is the image pushed up to some left invisible wall, climbs up and then rotates until so other edge hits the invisible wall. I believe I need to set a constant center. How do I do this and where in my code do I put the center? I've looked at many examples but it seems like this weird rotation keeps occurring. Here is my code:
def update_angle(self):
orig_car = self.car1
loc = orig_car.get_rect().center
car2 = pygame.transform.rotate(orig_car, self.angle)
car2.get_rect().center = loc
return car2
I had a similar problem to you, I managed to pull a small amount of code together to fix it. When you're blitting the car to the screen use this code:
rect = car2.get_rect(center=(200,200)) #Set the centre of rotation
SCREEN.blit(car2, rect)
It allows the image to rotate about a point, hope this helps!
I am currently working on a 2D platformer and the sprites that I have animate from the bottom left point of the animation and when I draw the animation using a x and y point it still animates from the bottom left, so when I draw the animation to the screen the sprite should get shorter but the sprites feet just lift up of the ground like this https://www.dropbox.com/s/ofeggmlcp4f6qsk/Animation_probs_video.mp4
I know the video is not high quality but so what.
His head should go up and down not his feet. If you guy's can help me I would be most greatful. I could also use a program that fixes that I have a Linux computer with a windows xp virtual box and I am using python 2.7 and pygame.
Thanks.
Assuming you are animating a series of rectangular sprites each being an instance of pygame.Surface, you will be adding the difference between the surface with the greatest height and the current sprite's surface to the y position every time you blit.
Find the height of the tallest sprite only once:
max_height = tallest_sprite.get_height()
Now while you are cycling through your sprints each frame with current_sprite:
screen.blit(current_sprite, (x, y+(max_height - current_sprite.get_height())
If framerate is an issue, you may want to calculate these differences beforehand and associate them with each sprite so you have one less get_height() call per frame.
Hi I am trying to make a punny cookie clicker type game called py clicker and made an invisible circle over the sprite which is a pie. How do I detect if the mouse is within the circle so when the user clicks it checks if it is in the circle and adds one to the counter?
If you know the x,y of the center of the circle and it's radius then you can calculate the distance from the center of the circle to your mouse pointer when you click. If it's greater than the radius then you are outside. There is a built in method that might help called math.hypot that will return the length between two points.
You could try pygame.sprite.collide_circle() . But you will need another Sprite with small radius and mouse position.
you can use the graphics library and use the method called getMouse.