#need help with rotation and collisions

1 messages · Page 1 of 1 (latest)

pallid harbor
#

hi, i'm very new to this so i don't really know how to present my problem but hope you understand. i want to make a 2d tank game (side scrolling not top down) and i managed to get the muzzle rotating to mouse position by using "look_at(get_global_mouse_position())" but i want it to stop at tank level or maybe 15 degrees above that so that it doesn't clip through the tank and be a bit more realistic, i tried different collision layers and masks for both the tank hoping that the tank would stop the muzzle from rotating but the muzzle just moves the tank if it touches it i guess because the tank has (move and slide) called. i'm sure it's a very simple think to implement but i'm just starting and my knowledge is very limited.

vital sandal
#

I am still pretty new to Godot but have you been able to try using the clamp() function to restrict the rotation angle of the muzzle? Something like:

muzzle_angle = clamp( muzzle_angle, -90.0, 90.0)

May need to adjust based on your code and setup.

There’s some documentation on the clamp function here: https://docs.godotengine.org/en/stable/contributing/development/core_and_modules/common_engine_methods_and_macros.html#clamp-a-value

pallid harbor
#

@vital sandal thank you so much, you just made my day