How to know how much time the player is in air (Roblox)? - lua

I just created a Roblox game of shooting. The main target of the game is to stay alive as long as possible. But I recently noticed while playing other games that people use mods for flying in air. (In simple words 'hacking').
If the people use that in my game also they might be the one and only winner always.
So I decided to check when a player is not touching any object (In air) for more than 5 seconds the the player should die.
But then I searched In Google if there are any ways that I can do that. But found none. If anyone know how to achieve that can please help me...
Thanks in advance

This is the result of my 1 minute google search, no idea what you searched for...
From: https://developer.roblox.com/en-us/api-reference/property/Humanoid/FloorMaterial
When the Humanoid is not standing on a floor, the value of this
property will be set to Air.
The code sample below demonstrates how to listen to when this property
changes using Instance:GetPropertyChangedSignal
So if the material changed to Air you start a 5 second timer.
If the player lands stop the timer. When the timer finishes, kill the player.
There are some comments that FloorMaterial might be problematic if the player is swimming. So probably use https://developer.roblox.com/en-us/api-reference/event/Humanoid/StateChanged to start and stop the timer.
That should give you plenty of starting points. I won't give you any code. Make yourself familiar with the examples and you'll come up with a solution quickly.

Related

SpriteKit: Should I pan the camera or move the background?

When building a game with SpriteKit, with a platformer game (like Doodle Jump for example), is it preferable to move the camera up, or the background nodes down ?
What is the standard practice in other frameworks ?
MOVE THE CAMERA!!!
One of the weirdest things about 2D game engines is that it often takes them a series of versions to get a camera.
They should be born with them.
SpriteKit was no different, it took forever to get a camera.
Now that it has one, never ever think of not using it.
Will make your life a million times simpler.
I can think of no exceptions, but look forward to being proven wrong.
move background was HOTFIX until proper cam support added.
use the cam. its easy and fun. no reason to not imo.

iOS game center game is out of sync

I've been building a game center game for iOS and it works great so far. I finally started testing the game and theres (obviously) some latency, which is causing the game to be out of sync.
Basically I have 2 players, each controlling a game character. The game character can shoot fireballs and iceballs etc. These attacks do damage, and they have effects. For example. the ice ball effect will freeze the opponent for 3 seconds if it makes contact. the fireball will do extended fire damage for 3 seconds.
so the problem is, when I was playing against my brother, because of the latency, my game said I had 40 health left and he was down to 0, while on his device, the game said I had 0 and he had 20.
This means that attacks were registering/colliding on one device (based on the positions of the characters/fireballs) and not on the other. and vice versa.
I'm currently using the default peer-to-peer game-center architecture. Would using a client-server architecture (one person becomes the server) solve this out-of-sync problem?
if not, what other options do I have with the game kit API?
I've found a solution to this problem.
Note: this will be a relatively long answer.
One thing that I did implement was the use of udp for some of my data transfers that are not as critical as others. For example, since I'm sending movement data about 10 times a second, I figured its ok if 1 or 2 of the 10 get lost once in a while.
Now to the actual problem:
So what was happening is the following- since I'm using a p2p architecture, both clients have a delay when they see the game 'world'. This means that on my device, I see the enemy player at a position that is delayed 100-200 milli seconds. (so he was actually there 100-200 ms in the past).
The problem with this, is when I shoot a projectile at the enemy, and I see a collision, if the collision was right on the edge of his sprite (his feet or head), in his screen, he was already past that position - PLUS - my fireball appears 100ms delayed on his screen. This means on his device, he was able to dodge my attack. This can happen a random number of times, but I'd guess its probably below 30% of the time. 70%, both devices see the collision.
The solution
What I came up with is to send a message to the other player when either device sees a collision. And remember, each device has no idea if the other saw a collision or not. So I have no way of knowing whether both devices saw a collision, or only 1, and the other saw that the attack was dodged.
This means I have to send a message to the other player every time theres a collision. Now, because of the way I've architected my game, when a collision is sent, I'm automatically applying the collision event (meaning, damage dealt, projectile effect that took place - like ice bolt freezing the player it collided with) This is problematic, because what if both devices saw the collision. That means both devices are sending each other a message of collision, and applying collisions again.
To get around this, I've added a "spell number" to each spell/attack, and when a collision happens, I save this number with the player that the collision happened with as the "last collision spell number". So if a collision takes place with that spell, the player knows he/she already collided with that specific object, so collision logic doesn't run twice.

speed up timer game in Xcode

hi i am building my first basic game in Xcode for the iPhone i have one issue its facing me
the game is snake eating food i need the correct way to speed up UIimageView .
i had try to speed up the NSTimer but ever time the level 1 work fine then when i go to level 2 the snake and the score not working correct ??
so please i need the correct way to increasing the speed of image without effecting the next level
or the correct way to speed up the timer ..
if any one can help me i am ready to sure the code with him by e-mail need some help pleeeeeeease .
It's not possible to synthetically speed up the iOS simulator.
Your only option is to increase the firerate of your NSTimer.

Input Delay at start of iOS game

When I run my iOS game on a device, for a minute from the start approximately there is a delay in input: when I touch the screen somewhere, the game recognizes that touch only after 2 to 3 seconds; the accelerometer also shows the current orientation from 3 seconds ago!
I know it's not my coding, because after the first minute (approximately), the game starts behaving correctly, with input recognized at real time.
I suspect it also has something to do with my game running slow, but I can't find what's causing it. Is there something general that could be causing the delay, or can it be something specific to my code?
There is so many reasons for this, but as a start try using Instruments to record the performance of the game, and u could postpone the actual start of the game a few seconds till everything gets properly loaded.
it is very likely that there is a loop somewhere that is doing quite more iterations than it is supposed to.

windows phone 7, xna, how do I sample the touch screen more regularly

ok, so apparently xna games can only run at 30fps, which is a shame, because our game on iphone looked alot better at 60...
at any rate, because the only way you can get information about the touch screen state is to get its current state, effectively this means you can only sample the touch screen at 30 fps.
even if our game has to run at 30fps, is there any way to get higher resolution sampling from the touch screen? maybe through callbacks? or by accessing a list of touch events with time stamps?
The function you are looking for is TouchPanel.GetState. It is a simple matter of calling this function at 60Hz.
To get 60Hz you could set Game.TargetElapsedTime to 1/60th of a second. This will give you two updates to every one draw (according to Shawn Hargreaves' post here) assuming you are VSyncing at 30FPS.
If you still want your game state updates to run at 30FPS (just doing touch input at 60FPS), then you could put those updates on a different thread. Start an update going on that thread on the first call to Game.Update, and wait for it to finish on the second one, and so on.
(You should note that normally XNA input must be done on the main thread (source). I assume this applies to Phone and to touch input.)
Alternately you could replace the Game class's timing yourself entirely (calling GraphicsDevice.Present yourself). It's not easy to do, but it's possible. A good place to start is to look at the Game class in Reflector.
(Disclaimer: I haven't tried any actual Phone-based development yet, so there may be some Phone-related gotchas I am unaware of.)
The sampling rate of 30fps is set for performance reasons.
Even if you could find a way to query for touches more frequently you still couldn't update the UI at a faster rate so I'm not sure what benefit you'd get.
Before spending too much time on trying to find a solution I'd test on an actual device to see how acceptable 30fps really is.

Resources