game-physics

how to control snake with only two keys i.e left and right

会有一股神秘感。 提交于 2021-02-05 08:36:25
问题 currently, i'm using all four keys to steer the snake left, right, up and down. I'm wondering how can i only use left and right key to move the snake around. if event.key == pygame.K_LEFT: snake.direction = 2 elif event.key == pygame.K_RIGHT: snake.direction = 3 elif event.key == pygame.K_UP: snake.direction = 0 elif event.key == pygame.K_DOWN: snake.direction = 1 def move(self): if self.direction is 0: self.dy = -self.block self.dx = 0 if self.direction is 1: self.dy = self.block self.dx = 0

Random movement pygame

天大地大妈咪最大 提交于 2021-02-05 07:40:20
问题 I'm trying to make a simple life simulator, and I need the "cells" to move almost randomly (with a few rules) across the screen. But the problem is, after a while they tend to bunch up in the upper-left corner of the screen. I tried to change a lot of things, like completely skipping the rules and making them move completely randomly, but they still bunch up. Is there some obvious problem in my code? Or should I be doing the movement completely differently? The code with irrelevant parts cut

Random movement pygame

天涯浪子 提交于 2021-02-05 07:40:19
问题 I'm trying to make a simple life simulator, and I need the "cells" to move almost randomly (with a few rules) across the screen. But the problem is, after a while they tend to bunch up in the upper-left corner of the screen. I tried to change a lot of things, like completely skipping the rules and making them move completely randomly, but they still bunch up. Is there some obvious problem in my code? Or should I be doing the movement completely differently? The code with irrelevant parts cut

How to make an object move in the path of an arc?

こ雲淡風輕ζ 提交于 2021-02-04 14:12:33
问题 I'm making a game where there should be a robot throwing ball-shaped objects at another robot. The balls thrown should fly in the shape of a symmetrical arc. Pretty sure the math-word for this is a parabola. Both robots are on the x axis. How can I implement such a thing in my game? I tried different approaches, none worked. The current system of moving things in my game, is like so: Every object has x and y co-ordinates (variables), and dx and dy variables. Every object has a move() method,

Calculate a 3D trajectory by start point, end point and height

放肆的年华 提交于 2021-01-29 18:55:45
问题 I've already figured out how to make a 3D trajectory using a start point and an angle. However, I am trying to make a trajectory from a start point, an end point, and a height. I tried taking the approach of a parabola on a 2D plane in a 3D space. I calculated the Prabola's A, B, and C values as well as the plane it's on given 3 points on the Parabola. However, I've had a few complications with this sort of calculation, I assume it has to do with the inability to properly calculate a Z-axis

Unity - raycast is clearly colliding but does not work?

血红的双手。 提交于 2021-01-05 11:06:23
问题 Ok I have 2 objects on the Default layer that I need to trigger a jump with when raycast collides. I can see that the raycast is intersecting the platform: And here is my collider on the platform: And yet nothing is printed with: Vector3 rotation = transform.forward; RaycastHit hit; Debug.DrawRay(new Vector3(transform.position.x, transform.position.y + 0.4f, transform.position.z), rotation, Color.green); if (Physics.Raycast(new Vector3(transform.position.x, transform.position.y + 0.4f,

Unity - raycast is clearly colliding but does not work?

微笑、不失礼 提交于 2021-01-05 11:03:24
问题 Ok I have 2 objects on the Default layer that I need to trigger a jump with when raycast collides. I can see that the raycast is intersecting the platform: And here is my collider on the platform: And yet nothing is printed with: Vector3 rotation = transform.forward; RaycastHit hit; Debug.DrawRay(new Vector3(transform.position.x, transform.position.y + 0.4f, transform.position.z), rotation, Color.green); if (Physics.Raycast(new Vector3(transform.position.x, transform.position.y + 0.4f,

Unity - raycast is clearly colliding but does not work?

十年热恋 提交于 2021-01-05 10:59:18
问题 Ok I have 2 objects on the Default layer that I need to trigger a jump with when raycast collides. I can see that the raycast is intersecting the platform: And here is my collider on the platform: And yet nothing is printed with: Vector3 rotation = transform.forward; RaycastHit hit; Debug.DrawRay(new Vector3(transform.position.x, transform.position.y + 0.4f, transform.position.z), rotation, Color.green); if (Physics.Raycast(new Vector3(transform.position.x, transform.position.y + 0.4f,

aframe-physics-extras: collision of dynamic entity with static gltf model

爷,独闯天下 提交于 2020-12-27 05:25:43
问题 I'm trying to catch collision event between a dynamic sphere and a static gltf model. I'm building the gltf entity the following way: const template = document.createElement('a-entity'); template.setAttribute('physics-collider', 'ignoreSleep: false'); template.setAttribute('collision-filter', 'collisionForces: false'); template.setAttribute('body', 'type:static; shape:hull'); // add position, scale, url etc // ... template.addEventListener('collisions', e => { // debugger; }) This code

Can't understand how to make character face mouse in PyGame

烈酒焚心 提交于 2020-12-23 12:10:53
问题 Below is what I have so far. At the moment, the player moves, and all I want it to do now is face the mouse cursor at all times (think Hotline Miami or other top-down games). I've used some code involving atan2 that I found online, but I barely understand what it does (finds the distance between the player and mouse somehow...) and my character just spins wildly offscreen until I get an 'Out of memory' error. Any help would be much appreciated, I've looked all over the internet and can't find