made raycast smaller

This commit is contained in:
2022-12-10 21:18:29 +01:00
parent bb05e7a4bd
commit 57cbbacc47
2 changed files with 6 additions and 7 deletions

View File

@@ -1,7 +1,7 @@
[gd_scene load_steps=5 format=3 uid="uid://ujfhvssvbgpg"] [gd_scene load_steps=5 format=3 uid="uid://ujfhvssvbgpg"]
[ext_resource type="Script" path="res://src/scene-scripts/player.cs" id="1_qehox"] [ext_resource type="Script" path="res://src/scene-scripts/player.cs" id="1_qehox"]
[ext_resource type="Texture2D" uid="uid://c3ep33iycax04" path="res://assets/textures/debug/dummy-player-normal.png" id="2_48656"] [ext_resource type="Texture2D" uid="uid://377657cxmdpa" path="res://assets/textures/debug/dummy-player-normal.png" id="2_48656"]
[sub_resource type="SpriteFrames" id="SpriteFrames_2x1cy"] [sub_resource type="SpriteFrames" id="SpriteFrames_2x1cy"]
animations = [{ animations = [{
@@ -31,6 +31,6 @@ current = true
zoom = Vector2(0.8, 0.8) zoom = Vector2(0.8, 0.8)
[node name="ray_cast_2d" type="RayCast2D" parent="."] [node name="ray_cast_2d" type="RayCast2D" parent="."]
target_position = Vector2(0, 128) target_position = Vector2(0, 100)
collision_mask = 2 collision_mask = 2
collide_with_areas = true collide_with_areas = true

View File

@@ -1,6 +1,5 @@
using Godot; using Godot;
using System; using System;
using System.Diagnostics;
public partial class player : CharacterBody2D public partial class player : CharacterBody2D
{ {
@@ -25,10 +24,10 @@ public partial class player : CharacterBody2D
public override void _Process(double delta) public override void _Process(double delta)
{ {
//set ray_cast target position //set ray_cast target position
if (Input.IsActionJustPressed("move_right")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(128, 0); if (Input.IsActionJustPressed("move_right")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(100, 0);
if (Input.IsActionJustPressed("move_left")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(-128, 0); if (Input.IsActionJustPressed("move_left")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(-100, 0);
if (Input.IsActionJustPressed("move_down")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(0, 128); if (Input.IsActionJustPressed("move_down")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(0, 100);
if (Input.IsActionJustPressed("move_up")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(0, -128); if (Input.IsActionJustPressed("move_up")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(0, -100);
//call event in raycasted object //call event in raycasted object
if (Input.IsActionJustPressed("ui_accept") && GetNode<RayCast2D>("ray_cast_2d").IsColliding()) if (Input.IsActionJustPressed("ui_accept") && GetNode<RayCast2D>("ray_cast_2d").IsColliding())