![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | siten0308 |
Hello,
new to Godot, coming from unity, i have been looking at tutorials to help me better understand the scripting, and the Engine structure especially the layer of nodes etc.
i am creating a simple 2d Platform, this platform has a node, with a child kinematic2d and the child has a sprite. I made a script and attached it to the Kinematic2d, which i am debating what is the difference if i attach it to the sprite or the kinematic2d? anyways, the real problem, is, i am looking at the documentation of godot:
already i found 2 problems, the 2/2 problem is really what i am asking, which is this code below:
using Godot;
using System;
public class KBExample : KinematicBody2D
{
[Export] public int RunSpeed = 100;
[Export] public int JumpSpeed = -400;
[Export] public int Gravity = 1200;
Vector2 velocity = new Vector2();
bool jumping = false;
public void getInput()
{
velocity.x = 0;
bool right = Input.IsActionPressed("ui_right");
bool left = Input.IsActionPressed("ui_left");
bool jump = Input.IsActionPressed("ui_select");
if (jump && IsOnFloor())
{
jumping = true;
velocity.y = JumpSpeed;
}
if (right)
{
velocity.x += RunSpeed;
}
if (left)
{
velocity.x -= RunSpeed;
}
}
public override void _PhysicsProcess(float delta)
{
getInput();
velocity.y += Gravity * delta;
if (jumping && IsOnFloor())
{
jumping = false;
}
velocity = MoveAndSlide(velocity, new Vector2(0, -1));
}
}
when i go to increase the RunSpeed variable from 100 to 700, it still goes the same speed, when i try and change the graivty or even the Jumpspeed, nothing increases or no difference in the movement of the KinematicBody2d, why is that? something i have to set or do something else after making the change? i just hit the “Play Project” button but nothing ever changes… in terms of jumping higher or running faster