Tag Info

Hot answers tagged

3

Whatever collision be, angular momentum is conserved. ie Iw = constant with the coefficient of restitution (in translation, i dont know if its said the same in rotation) u define, and with the moment of inertia, you should be able to figure it out. And i think this would similar to collisions in 1D, since only one axis is used :) Goodluck :)


3

If you desire a pure function like int ComputeDamage(Type a, Type b), instead of expressing the combinations of a and b in code, you can encode them as data in an associative dictionary or a table. A lookup will then be along the lines of damageTable[a][b] or damageMap.get(pair(a,b)). An immediate benefit of driving the logic via data is that it's easier to ...


3

First its good to note the difference between Colliders and Triggers Colliders - generally are intended to represent physics interactions, so objects "colliding with them" should not pass through one another. As opposed to... *Triggers* - as the name implies, "fire" off an event but don't carry the typical physics body interactions Triggers and colliders ...


2

Unity is pretty smart about keeping stuff around that you need in the future. What's more difficult is telling it when to get rid of stuff you don't need anymore. So yes, once this texture is loaded, it will recognize that and not load it again provided something hasn't removed it from memory in the meantime.


2

First off, are you aware of the command BroadcastMessage? It's not quite what you are asking for, but it's close and it happens to be named the exact terms you used. That command sends a message to all children, not siblings, but that means it will message all siblings if you use that command on the parent. So write something like: ...


2

Two dot products, using the vector between their centers, tells you which corner is closest. A positive "Forward" dot indicates a front corner; negative is rear. A positive "Right" dot indicates a right corner; negative is left. If the distance between the selected corner and the friendly is less than Range, it is in-range. Nearest-corner test: This will ...


2

There are some problems with your approach. Unity doesn't support serialization of polymorphic custom classes not derived from ScriptableObject or MonoBehaviour. In other words, it doesn't matter where and how you initialized a field, if B if an instance of A it will be sliced of (or won't be serialized at all I don't remember exactly I need to check). ...


2

Your groundCheck Transform is a child of the player and rotates around the player when the player spins. The groundCheck's primary function is to provide a position to use when calling OverlapCircle(). This means it could be replaced as follows: public Vector3 groundCheckOffset = new Vector3(0f, -1f, 0f); // one unit down // ... grounded = ...


2

Let's rephrase your question: Given a rotation R, and a position p, we would like the rotated point p' to lie along the Z-axis (also known as the center of the camera). For this, we can use linear algebra: Compose the rotation matrix R from your euler angles. Solve the problem Rd = [0 0 1]^T, or | 0 | d = inv(R) | 0 | | 1 | d is ...


2

As others above have said, you need to generate texture coordinates for the top of your object. You can do it by hand (i.e. have your artist do it in their 3D software), or you can do it algorithmically. I've had good success using tri-planar mapping. There's a good explanation here. Essentially, you take the x, y, and z components of the normal and use ...


2

I've found that making a looping script works well for an attack timer, and avoids the problems that come with using a coroutine to time something. Bonus here is that you can use this anywhere in your scripts for an easy timer. private bool canAttack; //This gets changed when the enemy can try and shoot at you (ie. within range) private float newFireTime; ...


2

You're in luck. I did a full translation of Randy Gaul's 2D physics engine into C# and XNA. He hasn't really explained things well for beginners like me. For your answer, you should just multiply the cross product with the inverse of the inertia of the body. This is from my translation: angularVelocity += inverseInertia * Vector2D.Cross(contactVector, ...


1

Make the float move variable a class variable. Then create 2 methods which the left and right UI buttons will call on Pointer Down, e.g. MoveLeft() and MoveRight(). Inside them, set move = -1 for left and move = 1 for right. If you want the character to stop if the buttons aren't pressed, you can also make a StopMoving() method on Pointer Up for both ...


1

If you don't want them stacking up, just use a bool for a flag. bool inShootingLoop = false; //keep track of when the coroutine is running public void Shoot(){ if(!inShootingLoop) StartCoroutine ("ShootContinuous"); } public IEnumerator ShootContinuous() { inShootingLoop = true; //we're running, set this to make sure we don't start again ...


1

Sounds to me like what you need is to define a box in the middle of the screen, and only if the car moves outside of that box then the camera will move. That way the car has a bit of freedom to move without the camera moving, but as soon as it gets too far away from the center of the screen the camera does follow it. This is similar to the technique used in ...


1

There are lots of ways to do this, though MoveTowards seems reasonable for your purposes. Essentially, you'll want to determine some speed you want the camera to follow the car. Let's say that's float cameraFollowSpeed; Then you need to adjust that to be framerate independent with Time.deltaTime So now FollowCar's Update() your code is something like ...


1

Your code currently contains : public float jumpFocre = 500f; //... GetComponent<Rigidbody2D>().AddForce(new Vector2(0, jumpFocre)); Rigidbody2D.AddForce() takes a Vector2 as a parameter, so this can be changed to: public Vector2 jumpDirection = new Vector2(0f, 1f); public float jumpFocre = 500f; //... ...


1

From a programming perspective. I think matching individual items will not scale. Every unit, weapon, piece of armor, etc. should know about the different types of damage, multipliers, etc. that it can deal or absorb. The programming gets much easier and you can add new items in the future without having to be sure you got all of the mapping correctly. ...


1

You could sum it up like such: Pre-game install: You can't assume they are there. Post-game install: You can assume (hope) that the XNA 4.0 Redistributable installed correctly and the assemblies reside in their respected locations. If the scripting that the user will be doing is tested and run solely in game, then I would think that this is a safe route ...



Only top voted, non community-wiki answers of a minimum length are eligible