Why is move_and_slide() not working in Godot? - godot

In Godot engine version 3.4, move_and_slide isn't working.
extends KinematicBody2D
var velocity = Vector2(0,0)
func _process(delta):
velocity.x = (Input.get_action_strength("right")-Input.get_action_strength("left"))*100
velocity = move_and_slide(velocity,Vector2.UP)
When I run this code, the KinematicBody2D doesn't move. Does anyone know why?

The Answer is inside the Comment.
Blockquote I increased the multiplier and it works. Thank you so much. > Blockquote
The Velocity Multiplier is too low

Related

the identifier "velocity" isn't declared in the current scope

"the identifier "velocity" isn't declared in the current scope."
godot is showing this error in my code:
extends KinematicBody2D
func _physics_process(delta):
if Input.is_action_pressed("ui_right"):
velocity.x += 4
elif Input.is_action_pressed("ui_left"):
velocity.x += -4
for some reason, I can't find the reason why this happens
pls answer
maybe the problem is with my code as I am purely a beginner and i am using godot version-3.4.2

How to sense which direction my player object was hit from in Game Maker Studio 2

I'm making a 2D Platformer game in GMS 2 and I need to make my player face the direction that he was hit from when he dies. How do I sense which side he was hit from? I only need to sense right and left collision. Currently my code looks like this:
if (hp = 0) {
with (instance_create_layer(x, y, layer, obj_player_1_dead)) {
if (obj_laser_2.x < obj_player_1.x) {
image_xscale = 0.6
} else if (obj_laser_2.x > obj_player_1.x) {
image_xscale = -0.6
}
}
instance_destroy()
}
hp is my hit points variable.
I have instance_destroy(); at the bottom because I am destroying the object and creating a player_dead object.
Everything else works exactly how I want it to. This is the last thing before the game is done. Any help is appreciated. Thanks in advance!

Anchored sprite lags when the underlying sprite moves in Phaser

On this link there is an example of a game developed using Phaser
http://examples.phaser.io.
Your tank is a sprite with a turret sprite anchored on it:
// The base of our tank
tank = game.add.sprite(0, 0, 'tank', 'tank1');
tank.anchor.setTo(0.5, 0.5);
...
// Finally the turret that we place on-top of the tank body
turret = game.add.sprite(0, 0, 'tank', 'turret');
turret.anchor.setTo(0.3, 0.5);
..
Also notice the following in the update function that executes every frame:
turret.x = tank.x;
turret.y = tank.y;
Notice that when you accelerate, the turret lags a bit and catches up with the underlying tank sprite only when you reach zero velocity. How to fix this?
a little bit late.. you should consider that your sprite uses physics that renders in various sections. Try to see API DOCs preUpdate, postUpdate, Phaser.World.
So, in your case, if you use for instance ARCADE Physics, you should reload data of your x,y via body which belongs to arcade.physics, not other.
tank = game.add.sprite(0, 0, 'tank', 'tank1');
tank.anchor.setTo(0.5, 0.5);
game.physics.enable(tank, Phaser.Physics.ARCADE);
......
turret.x = tank.body.x;
turret.y = tank.body.y;

Spritebuilder sprite position changes

I have my game in spritebuilder, and I am trying to move a ball up every 0.005 seconds. I have an NSTimer doing that, but sometimes ball.position.y + 2 is different.
For instance, one time I play the game, the ball moves to the top of the screen at the speed I want it to. Then, without even closing the game, just opening the scene again, the ball moves at half of the speed, as if + 2 isn't as much at that time, or the NSTimer decides to run at half speed.
NOTE: This only happens on an actual device. I can't get it to happen in a simulator.
Does anyone know why this is happening?
Thanks.
EDIT: My code (abridged):
timer2 = NSTimer.scheduledTimerWithTimeInterval(0.005, target: self, selector: "updateTick", userInfo: nil, repeats: true)
My update function:
func updateTick() {
...
incrementBalls()
...
}
My incrementBalls() function:
for index in 0...balls.count - 1 {
balls[index].position = ccpAdd(_physicsBody.position, CGPoint(x: balls[index].position.x, y: balls[index].position.y + 2))
}
I fixed this by instead using the update method and doing some math to move the balls instead of the unreliable NSTimer.

GLSL practice midterm

I have this problem on a practice midterm that I don't understand.
void main(void){
int i;
for(i=0; i< gl_VerticesIn; i++){
gl_Position = gl_PositionIn[i];
EmitVertex();
}
EndPrimitive();
for(i=0; i< gl_VerticesIn; i++){
gl_Position = gl_PositionIn[i];
gl_Position.xy = gl_Position.yx;
EmitVertex();
}
EndPrimitive();
}
I have been reading documentation, and I think that this is part of a geometry shader, and I think it is inverting the x and y coordinates of each point, but I don't have any way to verify this. I tried checking it in a program and it made slight differences in the coloring of the scene, but it didn't seem to change the geometry at all, so if someone could help explain this that would be awesome. Thanks!
This is indeed a part of a geometry shader.
First part of the shader (ending with first EndPrimitive()) is simplest possible pass-through geometry shader that does absolutely nothing to the geometry.
Second part is almost the same, except for the swizzling with the xy. It duplicates geometry, but changing the x and y coordinates, so it effectively mirrors the image across the line that connects down-left and up-right corner of the screen.
So, geometry is being duplicated and mirrored across the diagonal of the screen.

Resources