mirror of
				https://github.com/mightypanders/GMTKJam2021.git
				synced 2025-11-04 11:09:50 +01:00 
			
		
		
		
	driving backwards
This commit is contained in:
		
							
								
								
									
										23
									
								
								Playa.gd
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								Playa.gd
									
									
									
									
									
								
							@@ -1,8 +1,8 @@
 | 
				
			|||||||
extends KinematicBody2D
 | 
					extends KinematicBody2D
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export var ACCELERATION = 50
 | 
					export var ACCELERATION = 60
 | 
				
			||||||
export var MAX_SPEED = 100
 | 
					export var MAX_SPEED = 150
 | 
				
			||||||
export var FRICTION = 30
 | 
					export var FRICTION = 50
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var velocity = Vector2.ZERO
 | 
					var velocity = Vector2.ZERO
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -13,23 +13,22 @@ func _ready():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func _physics_process(delta):
 | 
					func _physics_process(delta):
 | 
				
			||||||
	var direction = Vector2.UP.rotated(rotation).normalized() #Playerrotation nehmen ist sicherer
 | 
						var direction = Vector2.UP.rotated(rotation).normalized() #Playerrotation nehmen ist sicherer
 | 
				
			||||||
	var is_accellerating = Input.is_action_pressed("ui_up")
 | 
						var forward_backward = Input.get_action_strength("ui_up") - Input.get_action_strength("ui_down")
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	if is_accellerating:
 | 
						
 | 
				
			||||||
		velocity = velocity.move_toward(direction * MAX_SPEED, ACCELERATION * delta)
 | 
						if forward_backward != 0:
 | 
				
			||||||
 | 
							velocity = velocity.move_toward(direction * MAX_SPEED * forward_backward, ACCELERATION * delta)
 | 
				
			||||||
	else:
 | 
						else:
 | 
				
			||||||
		velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
 | 
							velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
	var steer_dir = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
 | 
						var steer_dir = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
	if steer_dir != 0:
 | 
						if steer_dir != 0 && velocity.length() > 0:
 | 
				
			||||||
		var direction_new = direction.rotated(PI/2 * steer_dir * delta)
 | 
							var direction_new = direction.rotated(PI/1.5 * steer_dir * delta)
 | 
				
			||||||
		print(PI/8 * delta)
 | 
							print(velocity.length())
 | 
				
			||||||
		#print(velocity.angle_to(velocity.rotated(direction_new.angle())))
 | 
							#print(velocity.angle_to(velocity.rotated(direction_new.angle())))
 | 
				
			||||||
		velocity = velocity.rotated(direction.angle_to(direction_new))
 | 
							velocity = velocity.rotated(direction.angle_to(direction_new))
 | 
				
			||||||
		rotate(direction.angle_to(direction_new))
 | 
							rotate(direction.angle_to(direction_new))
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	
 | 
						velocity = move_and_slide(velocity)
 | 
				
			||||||
	#print(velocity)
 | 
					 | 
				
			||||||
	move_and_collide(velocity * delta)
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user