Re: Need help for handling turning with mouse, something like swamp
I don't get entirely what you're asking. But if direction is in degrees, if I understand this correctly, your code will break badly. Let's assume that the player did not move the mouse. That'll return (0, 0). then, mouse.get_rel()[0]-speed will be negative, so it will add a negative value onto the direction, which is probably not what you want. If you want to set the mouse sensitivity, something like this will work:
direction += mouse.get_rel()[0]*sensitivity
If you want to turn the player further if the mouse moves faster, eg if I move 20 coordinates in 0.2 seconds the player should be turned further than if I'd move 20 coordinates in 1 second:
# fps is a variable which specifies the frame rate
mouseXMovement = mouse.get_rel()[0]
# calculate the speed, in units per second. v = s / t wherein v the velocity, s the distance and t the time. fps is expressed as 1/t, (60 fps means one frame is 1/60 seconds). so, we get v = s/(1/fps) = s*(fps/1) = s*fps
speed = mouseXMovement*fps
# further calfulations go here
Another approach is to use an exponential function to calculate the new direction:
direction += sensitivity**mouse.get_rel()[0] # direction will increase faster with swifter movements
or another way:
direction += mouse.get_rel()[0]**sensitivity # direction will increase faster with swifter movements
I have no idea which of these methods works best. You'll have to experiment.
-- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector