0% found this document useful (0 votes)
6 views2 pages

Accel Tilt Cniorhindu

Uploaded by

sanmirguz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Accel Tilt Cniorhindu

Uploaded by

sanmirguz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

# Player.

gd

extends KinemacticBody

onready var player_mesh_pivot : Spatial = $MeshPivot


onready var mesh : Spatial = $MeshPivot/Semiproceduraldummy
onready var animation_tree : AnimationTree =
$MeshPivot/Semiproceduraldummy/AnimationTree
onready var camera_pivot : Spatial = $CameraPivot

var camera_offset : Vector3 = Vector3(0,6,0)


var camera_transform : Transform

var direction_forward_axis : Vector3


var direction_side_axis : Vector3
var direction : Vector3
var speed : float = 20.0
var velocity : Vector3
var last_velocity : Vector3
var acceleration : Vector3
var tilt : Vector3
var target_position : Vector3
var rotation_transform : Transform
var up_down_movement : Vector3

const GRAVITY : float = 10.0


const BOUNCE_FORCE : float = 20.0

_ready() -> void:


camera_pivot.set_as_toplevel(true)

_process(delta) -> void:


set_camera_follow()
get_camera_transform()
get_input()

_physics_process(delta) -> void:


calculate_velocity(delta)
find_velocity_facing_direction()
find_acceleration()
find_tilt_vector()
find_last_velocity()
move()
# apply_gravity()
rotate_towards_acceleration(delta)
rotate_towards_velocity(delta)
# blend_idle_walk()

func set_camera_follow() -> void:


camera_pivot.follow_me(translation + camera_offset)

func get_camera_transform() -> void:


camera_transform = camera_pivot.give_direction()

func get_input() -> void:


direction_forward_axis = (-Input.get_action_strength("move_forward") +
Input.get_action_strength("move_back")) * camera_transform.basis.z
direction_side_axis = (-Input.get_action_strength("move_left") +
Input.get_action_strength("move_right")) * camera_transform.basis.x
direction = (direction_forward_axis + direction_side_axis).normalized()

func move() -> void:


velocity = move_and_slide(velocity, Vector3.UP)

func calculate_velocity(delta) -> void:


if direction != Vector3.ZERO:
velocity = velocity.linear_interpolate(direction * speed, 3 * delta)
else:
velocity = velocity.linear_interpolate(Vector3.ZERO, 3 * delta)

func find_velocity_facing_direction()-> void:


if velocity != Vector3.ZERO:
rotation_transform = mesh. transform. looking_at(velocity, Vector3.UP)

func rotate_towards_velocity(delta) -> void:


if rotation_transform != null:
mesh.transform = mesh.transform. interpolate_with(rotation_transform, 3
delta)

func find_last_velocity() -> void:


last_velocity = velocity

func find_acceleration() -> void:


acceleration = velocity - last_velocity

func find_tilt_vector() -> void:


tilt = acceleration.cross(Vector3.UP)

func rotate_towards_acceleration(delta) -> void:


if tilt != null:
player_mesh_pivot.rotation = lerp(player_mesh_pivot.rotation, -tilt/5, 3 *
delta)

You might also like