![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Andrea |
Hello everybody,
i´m new here and I´m doing a small flipper game in order to learn how to code with Godot 3.
Up to now what puzzles me the most is a problem that occurs with collision shape, but it is something that doesn´t happens all the time: either I´m doing something wrong, or there is a bug with the physic engine.
The game starts with a ball (Rigidbody, mode rigid) laying on top of a spring (Rigidbody, mode character).When the player hit the down arrow, the spring is compressed down (the ball follows it, because gravity is enable) and when the button is released the spring come back to original position and push the ball into the game table.
enter link description here
Here´s the script for the spring movement:
extends RigidBody2D
export (float) var SPEED_UP
export (float) var SPEED_DOWN
const lower_point=850
const upper_point=720
func _ready():
pass
func _physics_process(delta):
if Input.is_action_pressed("ui_down") and position.y<lower_point:
set_linear_velocity(linear_velocity+Vector2(0,SPEED_DOWN))
elif Input.is_action_pressed("ui_down") and position.y>=lower_point:
set_linear_velocity(Vector2(0,0))
else:
if position.y<upper_point+2:
set_linear_velocity(Vector2(0,0))
position.y=upper_point
elif position.y>720:
var dist=position.y-upper_point
set_linear_velocity(Vector2(0,-SPEED_UP*dist))
#
if position.x>684 or position.x<682:
position.x=683
It works fine most of the time, but then magic happens: somehow when the spring is in a lower position, the ball find a way to “push” the collision shape of the spring by side, and i dont mean the entire “spring” node (rigid body + sprite + collision), but the collision shape only (at least it looks like that): in fact, the sprite remain perfectly in position, and even if i attach another sprite as a child of said uncooperative collision shape I cant see any strange movement.
However from the moment in which the first ball move the collision shape away, all the further ball simply fall through the spring: collision shape is no more there!
Hope i made myself clear, do somebody know what´s happening here?