Skip to content

Instantly share code, notes, and snippets.

@pixelpicosean
Created April 9, 2017 06:17
Show Gist options
  • Save pixelpicosean/6e2a96b68f337502667ce0f0a95b77de to your computer and use it in GitHub Desktop.
Save pixelpicosean/6e2a96b68f337502667ce0f0a95b77de to your computer and use it in GitHub Desktop.
[Zelda Camera] Zelda style camera script(from Dodgetgo) #tags: Godot
extends Camera2D
export(Vector2) var RoomSize;
export(NodePath) var Target;
export var ScrollSpeed = 2;
var Future_pos = Vector2();
var cam_pos = Vector2(0,0);
var is_translating = false;
func _ready():
set_fixed_process(true);
pass
func _fixed_process(delta):
var target_pos = get_node(Target).get_pos();
cam_pos = get_pos();
#cam_pos.x+=1;
if(!is_translating):
if(target_pos.y > cam_pos.y+RoomSize.y):
Future_pos.y += RoomSize.y
is_translating = true;
if(target_pos.y < cam_pos.y):
Future_pos.y -= RoomSize.y
is_translating = true;
if(target_pos.x > cam_pos.x+RoomSize.x):
Future_pos.x += RoomSize.x
is_translating = true;
if(target_pos.x < cam_pos.x):
Future_pos.x -= RoomSize.x
is_translating = true;
else:
_transtition();
print(str(cam_pos)+":"+str(Future_pos))
#move_to(cam_pos);
set_pos(cam_pos);
func _transtition():
get_tree().set_pause(true);
if(cam_pos.y < Future_pos.y):
cam_pos.y += ScrollSpeed;
elif(cam_pos.y > Future_pos.y):
cam_pos.y -= ScrollSpeed;
elif(cam_pos.x < Future_pos.x):
cam_pos.x += ScrollSpeed;
elif(cam_pos.x > Future_pos.x):
cam_pos.x -= ScrollSpeed;
else:
get_tree().set_pause(false);
is_translating = false;
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment