Simple refactoring for duplicated logic call - refactoring

I'm working on a unity c# project and refactoring some of my messy physics codes recently.
There's a simple logic I'd like to refactor in one of my monobehaviour's update () method :
if (collision box dirty)
Check collision
move player using physics value
Check collision
In my game, Collision Box Size & center Position Changes very dynamically so that's why I need to check if collision box is dirty & do collision checking.
As you see I do same logic twice in a method, and I feel like it can be more simple(or clearer). Any little advice will be great help for a beginner programmer like me. Thanks in advance!

Related

Joint for physical gun slider?

I want to make it so when I fire my gun the slider shoots back and then comes forward like a real gun. However I don't know how I should start because I can't find any relevant information on Google and I don't know what to search. All I need is the logic behind how to do it, I can code it myself.
I would agree with zambari.
Just create an animation and play it when your guns gets fired.
Edit:
Since you are talking about 3D, you could either
move the pivot of the object to the point where the trigger would be attached. This way, all you need to do is change the objects rotation for the animation.
use joints
This is the best tool for VR guns with interactable parts. I HIGHLY recommend looking at this to ANYONE making a VR game
https://github.com/Oyshoboy/weaponReloadVR

Ive been working on a "mario like" game engine in p5.js, im having some serious trouble with collision avoidance

By collision avoidance, i mean stopping the player from walking through something. Like in mario, he can't just walk through the blocks. I technically succeeded in making this, but it's very very bad. The player often gets stuck on the block once the player hits it, and i cant figure out how to fix it. I put all the code together on an online p5.js editor, Here
In the code i linked, I'm trying to get the player to not go through any of the terrain constructions i make, the one i have currently set up is a red square named 'block1'
Stack Overflow isn't really designed for general "how do I do this" type questions. It's for specific "I tried X, expected Y, but got Z instead" type questions. But I'll try to help in a general sense.
You need to take a step back and break your problem down into smaller steps and then take those steps on one at a time. Can you get a simple program working that just shows two hard-coded rectangles that change color if they're colliding? Get that working perfectly before moving on.
Shameless self-promotion: I wrote a tutorial on collision detection available here. That's for regular Processing, but everything should be basically the same for P5.js. Generally you probably want to use grid-based collision detection to figure out which cell your player is in, and then use rectangle-rectangle collision detection to actually check whether the player has hit a block.
If you're having trouble, please debug your code and try to narrow your problem down to a MCVE and ask a specific technical question. Good luck.

Extending CAShapeLayer with physics attributes (or is there a better solution)?

First disclamer, I'm a complete n00b in terms of iOS programming, but have over 15 years of other OOP experience.
I've done extensive search thus far on what I'm trying to accomplish, but have not come up with definitive answer.
I'm trying to create effect of drawing straight lines (simular in effect to fruit ninja cuting motion) where it would draw a line between point a (beginTouch) and b (endTouch) regardless of the angle.
I was able to achieve it pretty easily with use of CAShapeLayer. It also very usefull as it supports some animation options that I would like to be able to apply on end result line.
But what I also need is an ability to emulate physics behavior with resulting line shape, such as bouncing, possibly deforming the line to emulate stretching, and apply some sort of destruction animation (fading/breaking appart).
I'm not sure if the CAShapeLayer is the best option to achieve this effect and if it is where do I look next on extending it or combining it with something else.
I know this is not a specific code example type of question, but expert oppinion is appreciate.
Cheers
Alex

Collision between wall and player controller

I'm using Farseer and XNA on on WP7. I have 2 objects in my game. The first one is a wall generated from a bitmap. The second one is a player controller - in fact it's just a circle object. This circle follows player's finger.
I need a certain behavior - probably it's very basic, but I can't figure out how to google it. It's a collision detection that just wouldn't allow the controller to come into the wall. It shouldn't bounce. It should just try to follow the finger but not enter the wall.
I know it's not hard to implement it on my own, but if I'm using a physics engine and it happens to offer such a functionality it would be a shame not to take advantage of it. :)
you need to use a BoundingBox object, and check collision VS the object (you should create a BoundingSphere wrapping it)
http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series2/Collision_detection.php

Android UI Mathematics required for the implementation

Can someone tell me what would be the math required for moving around the small ball in the bar(meter) according to the touch motion.... I needed a clear idea on the logic..
The logic depends on how you want to model the interaction between the finger and the ball. Is it moving through a fluid, like a ball bearing? A gravitational field? Do you want it to decelerate as if under the influence of friction from the sides of the bar? Or do you want to simply have the ball track the finger, without fancy damping of the motion?
My point is that the "logic" can be pretty complicated, depending on how you decide to model it. I'd recommend looking for something canned in JavaScript before coding it yourself.

Resources