I am starting with phaser and I want to make a character and some rocks, I want these rocks to be moved by this character.
My intention is that when the character is touching the rock he can't go trough it and he can move it in the direction he is pointing.
Any idea how can I do it? Tell me some functions or Objects to use.
Depending on the physics system used, You will need to use a collision function. In Arcade physics this code would be in your update function:
game.physics.arcade.collide(player, rock, pushRock);
Then you would declare a function pushRock, that will handle what happens when your player collides/touches the rock. In your case, push the rock in the direction that the player is facing.
I recommend looking here and searching around, where you might find some more help or examples.
Related
I want to make a game with core magic elements, and one of the spells includes firing a beam of wood that can twist and turn as it attacks the enemy. This twisting and turning are controlled by the reticle, but the projectile will move fast so the control would not be extremely easy to master. I just want to know if it is possible. The engine I'm using is Unity and the language is C#.
Basically anything is possible, but you might have to cheat a little.
If it is a beam of wood, like you are creating an entire tree, I would start with a line renderer. You could give it a tree texture that repeats instead of stretches, and control the the path it takes with some code, and you would have a fairly compelling tree. If it is a 3D game, you could instantiate cylinders along the path, and it would still be moderately compelling.
I am working in GDScript, and I'm trying to get the player to aim their weapon in the direction of the mouse cursor. The look_at() function is great, but it's not the smooth movement I'm looking for.
So, instead I've been experimenting with the lerp() math operation to make it smooth... but its very jittery and buggy movement which is obviously not ideal.
func _process(delta):
`rotation_degrees = lerp(rotation_degrees,rad2deg(get_angle_to(get_global_mouse_position())),aim_speed)
`
1 See the image of my code here.
I can't work out if I'm doing something really stupid as I'm fairly new to Godot. Any help would be massively appreciated!
Please use_physics_process() instead of _process()
_process runs at the fastest possible rate whenever it gets the CPU. That makes it jittery. It is not ideal for player movements since you will need consistency in your frames.
_physics_process() is consistent as it is frame independent and is ideal for player movement.
if you want more details I recommend you check this video by Godot Tutorials
Btw look_at() should work just fine :)
I have a player, and I want to be able to detect when they are near a ball so they can press 'E' to kick it.
I'm new to godot and I'm probably just dumb but I can't figure out how to get the position of another object.
I have 3 separate scenes: MainScene(Node2D), Player(KinematicBody2D), and Ball(RigidBody2D). I want to attach a script to one of the scenes that detects how close the Player is to the Ball so they can kick it.
I'm not sure if I should attach the script to the MainScene, the Player scene, or the Ball scene and to be honest, I'm not entirely sure how the code should look. I'm not very familiar with the functions and the node/scene hierarchy is a little confusing.
I am familiar with Python, I just think I'm overwhelmed with this engine (its my first time using a game engine) and I'm having a bit of a tough time grasping it.
Any help would be greatly appreciated!
Side-quest: If you are feeling extra helpful I also need to figure out how to stop a RigidBody2D object from moving until the player hits 'E' on it to kick it!
For this you want an Area2D, which is purpose-built for "detecting nearby objects" without interacting with them physics-wise. Have an Area2D as a child of the Player node and connect the Player node to that Area2D's body_entered signal. Here's a tutorial on using Area2D for further info; this tutorial also links to various other tutorials that could be helpful.
i think you maybe use function
get_overlapping_bodies()
(of Area2D node) for detect another areas or body
So, I have been working in Unity but I've decided it's time to change to something I know better: JavaScript. I've been considering switching to Phaser.js but I have some questions regarding an issue I've been having even in Unity and that I found no solution to at the moment while searching on the internet. I have no code to provide as I haven't yet started actually programming in Phaser, so I'll try to be explicit.
My game idea basically revolves around some lights that change colors. The sprites I have for the lights look identical, but just with different colors, but not entirely (only parts of them are colored differently). The problem is that my game has many different colored lights and it has to change between them. Like, if one light is red and you click on it, it becomes green, for example. Creating and loading so many sprites that look almost the same seems like a bad practice, and I wonder if there is a way to change the color of a sprite or a part of the sprite by code. I know that Phaser doesn't support svg and that svg in games is a bad idea in general because of performance issues but it would have saved me a lot of time to just add the generated svg code of the sprites I use and just change the fill of the parts I want.
So, my question is: what are the best alternatives (if any) to using multiple sprites or how can you change the color of specific parts of them?
Another alternative, depending upon your light sprites, is to use Phaser's tinting capabilities.
Both sprites and images in Phaser can be tinted, and since Phaser supports sprite grouping, even if you wanted to change only a part of the image you could easily have each displayed object consist of two sprites, one of which is the same for all lights (the part that doesn't change) and another that is also shared, but tinted.
Phaser 3 example of tinting an image:
this.add.image(300, 300, 'pixel').setTint(0xff0000);
Phaser 3's setTint() documentation.
Phaser 2 CE example of tinting a sprite, in case you're looking at using this version:
sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'atlas', 'greenJellyfish0000');
sprite.tint = Math.random() * 0xffffff;
If the lights don’t have to move, then you can just have a few images and change their src’s. Alternatively, I believe you could have it so that when the sprite is clicked it changes to a different looking animation. That is, after all, the point of a spritesheet, isn’t it?
I'm newbie in programming world especially in webots.
Do you guys have any ideas/tutorial to move e-puck robot to a specific position in webots?
In my case, I'm trying to move the e-puck robot to the start position and when the robot finish performing wall following behavior, it will stop at the same position as start.
I'm searching for the ideas/tutorial to solve the problem, but in the end, I'm stuck. Can anyone help me?
Thank you.
I recommend you to take a look at the e-puck curriculum for Webots, particularly at the advanced part:
http://en.wikibooks.org/wiki/Cyberbotics%27_Robot_Curriculum/Advanced_Programming_Exercises
The idea is the following: if you would like to do this in real conditions, implementing the odometry of the robot is a first step. A "goto" function based on the odometry would be the second step. The link contains information about this.
Ultimately, taking care of the other sensors (distance sensors, etc.) is the best solution, but it requires to do "SLAM". In this case, you can link your controller with a SLAM library (e.g. gmapping or Karto):
http://en.wikipedia.org/wiki/Simultaneous_localization_and_mapping
If you don't care about realism, you can get the absolute coordinates of the robot (using a Supervisor, or a GPS+Compass device). Writing a "goto" function on this is trivial.