I am trying to make a waterful ring toss game, but I have difficulty applying power from one point to all objects in the game.
Basically, what I want to do is to add force to all objects located between x and y points to move by applying force according to their positions.
I've been doing research on Unity forums, Stackoverflow, and Unity documents for a while, but I haven't been able to find what should ı do or use.
I'm looking for resources or suggestions to help me solve this problem. I apologize in advance if I asked the wrong question. This is my first question on this platform.
Here is an example screen:
The solution I found thanks to the comments:
if (buttonPushed == true)
{
for (int i = 0; i < ringObject.Count; i++)
{
ringObject[i].GetComponent<Rigidbody>().AddForceAtPosition(Vector3.up * force, transform.position);
buttonPushed = false;
}
}
Simple way
You put your objects in a list and iterate over them and do whatever you want to do in a if statement in that loop.
Harder way.
Create an object in that area with a collider and get callbacks when your object collide with that big collider object.
Related
I don't want my player to be able to walk off ledges. I did this by shooting a single raycast downwards in front of the player, and if ground is NOT hit, then ignore input.
However this is jarring, especially if you diagonally walk along an edge you just completely stop, rather than 'slide' along it.
So I thought I could add two raycasts, one per side to detect which side the ledge is, then allow movement (or steer) the player as applicable.
The problem is I'm not sure how to proceed from here. I'm using a character controller for movement, my current code is like:
velocityXZ = velocity;
velocityXZ.y = 0; // we deal with gravity elsewhere
velocityXZ = inputDir * playerSpeed;
if (facingDropLeft || facingDropRight) {
velocityXZ.x = 0;
velocityXZ.z = 0;
}
velocity = new Vector3(velocityXZ.x, velocity.y, velocityXZ.z);
// handle gravity
charController.Move(velocity * Time.deltaTime);
Could anyone offer some insights into what direction to look into, or methods I will need?
I think that if you want to accomplish an enjoyable result you should use invisible walls. I think that probuilder can help you.
This is the approach I would have with this type of problem.
Use boxes to make wall than turn off the mesh renderers this will make invisible walls
So, I am working on some level generation stuff in Unity, and I have some cubes spawning around the world. The way I have it working right now, is that each floor tile checks if there is 'air' around it and if so, it spawns a wall. But, if I have a situation where this is an air block between two floors, it'll spawn two walls.
Is there a way I can check if there is multiple in the same position, but keep one from destroying?
Thanks!
p.s Also worth nothing, I place the walls using Raycasts, so the floor will check in 4 directions using one hit. I figure it's checking all 4 directions without stopping when it places a cube. So, may be an issue...
U can try making a overlapsphere where the raycast hits, that way all the objects in a certain radius get detected (so also objects that are in each other)
void GetWalls(Vector3 raycastTargetPosition, float radius)
{
Collider[] hitColliders = Physics.OverlapSphere(center, radius);
int i = 0;
while (i < hitColliders.Length)
{
hitColliders[i].SendMessage("AddDamage");
i++;
}
}
I am working on the game. and I want to know that position (2,2,5) has an object or not?
whenever i place a object at that position it should debug YES.
Please help me to solve my doubt.
Hey you can use the unity Physics.CheckSphere method.
The code would look something like this.
Vector3 pos = new Vector3(2,2,5);
float radius = 4f; //Radius to check in;
if(Physics.CheckSphere(pos,radius))
{
//Found
print("Found Object");
}
You would need to put this in some sort of repeating function I'm guessing. Also it may be important to pass in a LayerMask to the checkSphere method so that you only detect specific objects, not the ground for ex.
I am using Minecraft Forge and I want to know how to get the coordinates of a Block or an Item that the player is holding or looking at. Or It can also be just a block that the player just broke. In any case, I need to get those coordinates to be able to change them in a way that makes y=Sin(x) and I would keep looping and spawning copies of the same item so that it plots the Sinus function.
I would really appreaciate your help.. I am stuck with this for days.
Best,
To get the block a player is looking at:
MovingObjectPosition mop = Minecraft.getMinecraft().renderViewEntity.rayTrace(200, 1.0F);
if(mop != null)
{
int blockHitSide = mop.sideHit;
Block blockLookingAt = worldObj.getBlock(mop.blockX, mop.blockY, mop.blockZ) ;
}
The block variable would be blockLookingAt
Also, you may want to check out http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/
So, I've created a ring of SKSpriteNodes which are essentially rectangles that are joined together using pin joints. I'd like to suspend this ring inside of an SKShapeNode circle. I have connected each of the nodes to the SKShapeNode using SKPhysicsJointLimit's.
This all works fine, and I get the effect that I'm looking for if I set the maxLength to the "right" number, which I determine subjectively.
I've stored all of the limit joints inside of an Array, so I can get easy access, and I've added them to the physicsWorld.
All of this works properly and as expected, though it took a little work to get the code right. These things are picky!
Now, what I'd really like to do is set the maxLength equal to some large number and then gradually reduce that number over time so that the ring goes from "hanging loosely" to "pulled taut"
I've tried a variety of approaches -- none of which seem to work. First, I tried:
SKAction *tighten = [SKAction customActionWithDuration:1 actionBlock:^(SKNode *node, CGFloat elapsedTime) {
CGFloat t = elapsedTime/duration;
CGFloat p = t*t;
CGFloat newLimit = fromLimit*(1-p) + toLimit*p;
for (int i = 0; i < _connectors.count; i++){
[[_connectors objectAtIndex:i] setMaxLength:newLimit];
}
}];
[_ring runAction:tighten];
but this simply didn't do anything at all.
I finally realized that you don't appear to be able to change the properties of a joint after it has been added to the physicsWorld. So, I tried something like this in the update method of the scene:
[scene.physicsWorld removeJoint:[_connectors objectAtIndex:i]];
[[_connectors objectAtIndex:i] setMaxLength:newLimit];
[scene.physicsWorld addJoint:[_connectors objectAtIndex:i]];
but, this didn't work either. It threw the error:
'Cant add joint <PKPhysicsJointRope: 0x114e84350>, already exists in a world'
even though I've clearly removed it. So, I don't really know where to go from here. The documentation on joints and the existing material on the internet is very thin. I suppose the next thing I would try is removing all joints and et-adding them, but that's going to be a huge pain.
Any thoughts would be really quite helpful!
As noted by OP it appears the joint must be removed from physics world before the change applies. The below worked for me.
for joint in joints
{
physicsWorld.removeJoint(joint)
joint.maxLength = yourNewValue
physicsWorld.addJoint(joint)
}