Compare commits
	
		
			No commits in common. "9c90404a7f5aabedb91091873e6c509d8fa66548" and "5d7d4e90bc92e177b2b0c3bb39537d71fa5939cc" have entirely different histories.
		
	
	
		
			9c90404a7f
			...
			5d7d4e90bc
		
	
		
					 4 changed files with 40 additions and 65 deletions
				
			
		| 
						 | 
					@ -154,7 +154,7 @@ transform = Transform3D(0.065, 0, 0, 0, 0.065, 0, 0, 0, 0.065, 0, 0, 0)
 | 
				
			||||||
script = ExtResource("2_ksje8")
 | 
					script = ExtResource("2_ksje8")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="Skeleton3D" parent="rig" index="0"]
 | 
					[node name="Skeleton3D" parent="rig" index="0"]
 | 
				
			||||||
bones/0/rotation = Quaternion(0.10507, 0, 0, 0.994465)
 | 
					bones/0/rotation = Quaternion(0.0861766, 0, 0, 0.99628)
 | 
				
			||||||
bones/1/rotation = Quaternion(-0.0891896, 1.18734e-07, -1.06322e-08, 0.996015)
 | 
					bones/1/rotation = Quaternion(-0.0891896, 1.18734e-07, -1.06322e-08, 0.996015)
 | 
				
			||||||
bones/2/rotation = Quaternion(0.0133933, -1.19199e-07, 1.5966e-09, 0.99991)
 | 
					bones/2/rotation = Quaternion(0.0133933, -1.19199e-07, 1.5966e-09, 0.99991)
 | 
				
			||||||
bones/3/rotation = Quaternion(-0.00997737, 0.100365, -0.694951, 0.711948)
 | 
					bones/3/rotation = Quaternion(-0.00997737, 0.100365, -0.694951, 0.711948)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,6 @@
 | 
				
			||||||
extends CharacterBody3D
 | 
					extends CharacterBody3D
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const SPEED = 5.0
 | 
					const SPEED = 5.0
 | 
				
			||||||
const JUMP_VELOCITY = 4.5
 | 
					const JUMP_VELOCITY = 4.5
 | 
				
			||||||
@export var horiz_sens = 0.25
 | 
					@export var horiz_sens = 0.25
 | 
				
			||||||
| 
						 | 
					@ -25,7 +26,6 @@ func _process(_delta):
 | 
				
			||||||
func _input(event):
 | 
					func _input(event):
 | 
				
			||||||
	# Handle the rotation of the camera using mouse movement.
 | 
						# Handle the rotation of the camera using mouse movement.
 | 
				
			||||||
	if event is InputEventMouseMotion:
 | 
						if event is InputEventMouseMotion:
 | 
				
			||||||
		# Side to side, first player object then player visuals.
 | 
					 | 
				
			||||||
		rotate_y(deg_to_rad(-event.relative.x * horiz_sens))
 | 
							rotate_y(deg_to_rad(-event.relative.x * horiz_sens))
 | 
				
			||||||
		$CameraMount.rotate_x(deg_to_rad(-event.relative.y * vert_sens))
 | 
							$CameraMount.rotate_x(deg_to_rad(-event.relative.y * vert_sens))
 | 
				
			||||||
		$grape_man.rotate_y(deg_to_rad(event.relative.x * horiz_sens))
 | 
							$grape_man.rotate_y(deg_to_rad(event.relative.x * horiz_sens))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,82 +1,55 @@
 | 
				
			||||||
extends CharacterBody3D
 | 
					extends Node3D
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var rng = RandomNumberGenerator.new()
 | 
					var rng = RandomNumberGenerator.new()
 | 
				
			||||||
@export var target_location_xz = global_transform.origin * Vector3(1, 0, 1)
 | 
					var spin_amount = 0
 | 
				
			||||||
@export var location_xz = global_transform.origin * Vector3(1, 0, 1)
 | 
					var spinning = false
 | 
				
			||||||
@export var target_direction_xz = (transform.basis * Vector3(1, 0, 1)).normalized()
 | 
					var wait_time = 0
 | 
				
			||||||
@export var direction_xz = (transform.basis * Vector3(1, 0, 1)).normalized()
 | 
					 | 
				
			||||||
var task = "idle"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Percentage chances of the character performing certain actions while idle.
 | 
					 | 
				
			||||||
@export var walk_chance = 0.1
 | 
					 | 
				
			||||||
@export var spin_chance = 0.2
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@export var walk_speed = 0.5
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Rate at which character corrects their direction after going off course (percentage).
 | 
					 | 
				
			||||||
@export var dir_correction_rate = 0.95
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Margin of accuracy to which the character will correct their direction when off course (radians).
 | 
					 | 
				
			||||||
@export var dir_accuracy = deg_to_rad(0.1)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Get the gravity from the project settings to be synced with RigidBody nodes.
 | 
					 | 
				
			||||||
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Called when the node enters the scene tree for the first time.
 | 
					# Called when the node enters the scene tree for the first time.
 | 
				
			||||||
func _ready():
 | 
					func _ready():
 | 
				
			||||||
	pass
 | 
						pass # Replace with function body.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
 | 
					# Called every frame. 'delta' is the elapsed time since the previous frame.
 | 
				
			||||||
func _process(delta):
 | 
					func _process(delta):
 | 
				
			||||||
	location_xz = global_transform.origin * Vector3(1, 0, 1)
 | 
						var task = "idle"
 | 
				
			||||||
	direction_xz = (transform.basis * Vector3(1, 0, 1)).normalized()
 | 
					 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	match task:
 | 
						match task:
 | 
				
			||||||
		"idle":
 | 
							"idle":
 | 
				
			||||||
			task = rng.randf_range(0, 100)
 | 
								task = rng.randi_range(0, 100)
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			# 3% chance to walk somewhere.
 | 
								if task <= 33:
 | 
				
			||||||
			if task <= walk_chance:
 | 
					 | 
				
			||||||
				task = "walk"
 | 
									task = "walk"
 | 
				
			||||||
				target_location_xz = global_transform.origin * Vector3(1, 0, 1) + (direction_xz * 16)
 | 
								elif task > 33 and task <= 50:
 | 
				
			||||||
			# 6% chance to rotate.
 | 
					 | 
				
			||||||
			elif task > walk_chance and task <= (walk_chance + spin_chance):
 | 
					 | 
				
			||||||
				task = "spin"
 | 
									task = "spin"
 | 
				
			||||||
				var rotation_angle = rng.randf_range(-2*PI, 2*PI)
 | 
								elif task > 50:
 | 
				
			||||||
				var rotation_vector = Vector3(cos(rotation_angle), 0, sin(rotation_angle))
 | 
									task = "wait"
 | 
				
			||||||
				target_direction_xz = direction_xz + rotation_vector
 | 
					 | 
				
			||||||
			# 90% chance to idle.
 | 
					 | 
				
			||||||
			elif task > (spin_chance + walk_chance):
 | 
					 | 
				
			||||||
				task = "idle"
 | 
					 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		"walk":
 | 
							"walk":
 | 
				
			||||||
			# Get the direction to the target in z-x plane.
 | 
								pass
 | 
				
			||||||
			target_direction_xz = (location_xz.direction_to(target_location_xz) * Vector3(1, 0, 1)).normalized()
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			# Continue to correct direction to within a margin of dir_accuracy degrees.
 | 
					 | 
				
			||||||
			if direction_xz.angle_to(target_direction_xz) >= dir_accuracy:
 | 
					 | 
				
			||||||
				# Rotate towards destination at specified percentage rate. 
 | 
					 | 
				
			||||||
				rotate_y(direction_xz.angle_to(target_direction_xz) * dir_correction_rate)
 | 
					 | 
				
			||||||
				
 | 
					 | 
				
			||||||
			if location_xz.distance_to(target_location_xz) <= (Vector2(direction_xz.x, direction_xz.z) * walk_speed).length():
 | 
					 | 
				
			||||||
				target_direction_xz = direction_xz
 | 
					 | 
				
			||||||
				target_location_xz = location_xz
 | 
					 | 
				
			||||||
				task = "idle"
 | 
					 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		"spin":
 | 
							"spin":
 | 
				
			||||||
 | 
								if !spinning:
 | 
				
			||||||
 | 
									var spin_amount = rng.randi_range(-360, 360)
 | 
				
			||||||
 | 
									spinning = true
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
								if spin_amount > 0:
 | 
				
			||||||
 | 
									rotate_y(5)
 | 
				
			||||||
 | 
									spin_amount -= 5
 | 
				
			||||||
 | 
								elif spin_amount < 0:
 | 
				
			||||||
 | 
									rotate_y(-5)
 | 
				
			||||||
 | 
									spin_amount += 5
 | 
				
			||||||
 | 
								else:
 | 
				
			||||||
				task = "idle"
 | 
									task = "idle"
 | 
				
			||||||
 | 
									spinning = false 
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
							"wait":
 | 
				
			||||||
 | 
								# Idle Animation goes here!
 | 
				
			||||||
 | 
								wait_time += 1
 | 
				
			||||||
 | 
								if wait_time == 100:
 | 
				
			||||||
 | 
									task = "idle"
 | 
				
			||||||
 | 
									wait_time = 0
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func _physics_process(delta):
 | 
					 | 
				
			||||||
	# Add the gravity.
 | 
					 | 
				
			||||||
	if not is_on_floor():
 | 
					 | 
				
			||||||
		velocity.y -= gravity * delta
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
	# Walk to target location.
 | 
					 | 
				
			||||||
	if location_xz.distance_to(target_location_xz) > (Vector2(direction_xz.x, direction_xz.z) * walk_speed).length():
 | 
					 | 
				
			||||||
		velocity.x = direction_xz.x * walk_speed
 | 
					 | 
				
			||||||
		velocity.z = direction_xz.z * walk_speed
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	move_and_slide()
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,11 +6,13 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_b3srs"]
 | 
					[sub_resource type="CapsuleMesh" id="CapsuleMesh_b3srs"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="Villager" type="CharacterBody3D"]
 | 
					[node name="Node3D" type="Node3D"]
 | 
				
			||||||
script = ExtResource("1_ardgw")
 | 
					script = ExtResource("1_ardgw")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
 | 
					[node name="RigidBody3D" type="RigidBody3D" parent="."]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="CollisionShape3D" type="CollisionShape3D" parent="RigidBody3D"]
 | 
				
			||||||
shape = SubResource("CapsuleShape3D_s4x8n")
 | 
					shape = SubResource("CapsuleShape3D_s4x8n")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="CollisionShape3D"]
 | 
					[node name="MeshInstance3D" type="MeshInstance3D" parent="RigidBody3D/CollisionShape3D"]
 | 
				
			||||||
mesh = SubResource("CapsuleMesh_b3srs")
 | 
					mesh = SubResource("CapsuleMesh_b3srs")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue