I
I
Igor2016-06-07 12:25:34
JavaScript
Igor, 2016-06-07 12:25:34

How to implement attraction (gravity) to the earth, provided that you are not standing on the object?

linewire.ru/t/Mario_game/Mario_game.html
8fff5571065d45e398b5fe9e05a93985.png
I think to register if mario.Y is above the "ground", then turn on the "gravity" mario.Y=20, for example, it's not clear how to check that I'm not standing on the surface of some stone or something else anyone coord.top.
there are a lot of objects, I won’t prescribe in the condition of each, can I make an array and check the array or what?
Can you show an example of the code please?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
maaGames, 2016-06-07
@IgorBee

Check with each stone. But not in general with every stone on the level, but only with those that are "nearby". Conventionally, you can divide the level into cells and in each cell there are several stones. You will only need to check collisions with those stones that are in the same cell as the player.

A
Alexander Bulgakov, 2016-06-07
@alebul

um, in physical engines it is done something like this - there is a dynamic object, given forces act on it, for example, gravity, they always act. And there are static objects on which these forces do not act. Plus a special property of type collision, that is, interactions with other objects. Push them away, just don't let them through, etc. So in your case, stones, earth and other things that should not move are static objects with a collision, and mario is a dynamic object that is affected by the force of gravity and other movements.

A
Alec Onim, 2016-06-07
@Caitiff_One

you check before moving down under the influence of gravity whether there is an object there, if there is, then there is nowhere to move, you are standing, speed = 0. something like this if in a nutshell

G
Greg Popov, 2016-06-07
@Gregpopov

Add a state
like onLand = true||false
for Mario

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question