0 votes

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 jumpspeed = -500
var speed = 500
var velocity = Vector2.ZERO
var friction = 0.1
var acceleration = 0.5
const wall
maxacceleration = 5
const wall
maxspeed = 0
var can
jump = true
var doublejump = 0
var max
doublejumps = 1
var slow
time = true
var chainvelocity = 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 physicsprocess(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 

here code for grapple

in Engine by (77 points)
edited by

1 Answer

+1 vote

I think you should be more specific.
Try adding information on how you are dong this like are you using a kinematic character or a rigid body etc

by (1,097 points)

oh thank I did not notice that here all the info
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 jumpspeed = -500
var speed = 500
var velocity = Vector2.ZERO
var friction = 0.1
var acceleration = 0.5
const wall
maxacceleration = 5
const wall
maxspeed = 0
var can
jump = true
var doublejump = 0
var max
doublejumps = 1
var slow
time = true
var chainvelocity = Vector2(0,0)#useful for grapple
const CHAIN
PULL = 50#useful for graple

    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 physicsprocess(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 

code for grapple

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.