Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ashish |
Hello everyone,
I am doing project where I mimic drawing of lines through strokes of a a brush. The brush is a KinematicBody2D which has a trailing line behind it. The line is formed by a $Line by adding points as the brush moves and mimics providing strokes. The brush’s moves is restricted by walls which are made up of StaticBody2Ds.
Here is the Scene structure:
https://drive.google.com/file/d/1w7aoGGGJbStMnAoHp_VgybDgexSENRB2/view?usp=sharing
extends KinematicBody2D
onready var line = get_node("../line")
var speed = 250
var velocity = Vector2(0,0)
var use_slide = true
var adjust =Vector2(10, 0)
var old_position
var carry_on = true
var strokes = 100
func get_input():
velocity = Vector2()
old_position = position
if Input.is_action_pressed('ui_right'):
velocity.x += 1
if Input.is_action_pressed('ui_left'):
velocity.x -= 1
if Input.is_action_pressed('ui_down'):
velocity.y += 1
if Input.is_action_pressed('ui_up'):
velocity.y -= 1
velocity = velocity.normalized() * speed
func _physics_process(delta):
get_input()
var temp = get_viewport().get_mouse_position()
move_and_slide(velocity)
line.add_point(old_position)
line.add_point(position)
The problem is that although the lines do get traced as I move the KinematicBody2D, they all disappear together after a finite lapse of time. After the lines disappear, the lines do not get traced anymore even after I move the brush (read, KinematicBody2D).
What am I doing wrong? How can I make the traced lines to remain persistent?
Please help.
Access denied on that link.
exuin | 2021-03-07 18:41
Sorry about that.
Have updated the access criteria.
Thanks for pointing that out.
I had missed out a few variables and a few lines of code. Have updated the code also.
Thanks in advance.
ashish | 2021-03-07 18:48
Do you get any errors in Godot?
exuin | 2021-03-07 19:14
Error in Godot.
Please see screenshot:
https://drive.google.com/file/d/1e15GJb6Oy604RWfsdOu556wRDRnFkGBQ/view?usp=sharing
ashish | 2021-03-08 02:22