![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | thoma |
Hi ! I have use this tutorial on youtube to learn how to use it.here the link
but I want my player node to stay in air like this look at 0:25 of the video :Here what I want
Thank you for your help and sorry for my english.
player node : Kninematic body
gravity : is an autoload
the grapple node is basicly like the tutorial is a sprite 2D who extend and have a tip woh is a Kninematic body.
code for the player:
extends KinematicBody2D
var jump_speed = -500
var speed = 500
var velocity = Vector2.ZERO
var friction = 0.1
var acceleration = 0.5
const wall_max_acceleration = 5
const wall_max_speed = 0
var can_jump = true
var double_jump = 0
var max_double_jumps = 1
var slow_time = true
var chain_velocity = Vector2(0,0)
const CHAIN_PULL = 50
func _input(event: InputEvent) → void:
if event is InputEventMouseButton:
if event.pressed:
# We clicked the mouse -> shoot()
$chains.shoot(event.position - get_viewport().size * 0.5)
else:
# We released the mouse -> release()
$chains.release()
func _physics_process(delta:float)->void:
#Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
get_input()
var walk = (Input.get_action_strength("d") - Input.get_action_strength("a")) * speed
#print(chain_velocity)
if $chains.hooked:
# `to_local($Chain.tip).normalized()` is the direction that the chain is pulling
chain_velocity = to_local($chains.tip).normalized() * CHAIN_PULL
if chain_velocity.y > 0:
# Pulling down isn't as strong
chain_velocity.y *= 0.5
else:
# Pulling up is stronger
chain_velocity.y *= 0.6
#
if sign(chain_velocity.x) != sign(walk):
# if we are trying to walk in a different
# direction than the chain is pulling
# # reduce its pull
chain_velocity.x *= 0.4
else:
# Not hooked -> no chain velocity
chain_velocity = Vector2.ZERO
velocity += chain_velocity
velocity.y += Globals.gravity * delta