Tag Info

New answers tagged

2

If storage size is your main concern, using vector<bool> is probably actually your best bet. This is because vector<bool> is optimized to use one bit per bool instead of one byte (see reference here). From there for file read/write just make sure to write the capacity of the vector<bool> to file then use the same one bit per bool/spell ...


1

during my experiments with HTML5 canvas and AABB I found exactly what you are experiencing. This did happen when I attempted to make a platform from adjacent boxes of 32x32 pixels. Solutions I attempted by order of my personal preference 1 - Divide movements by axis My current one, and I think I will continue my game with it. But be sure to check what I ...


3

I would combine the platform tiles into a single platform entity. For example, say you take the 3 tiles from the pictures and combine them into a single entity, your entity would have a collision box of: Left = box1.left Right = box3.right Top = box1.top Bottom = box1.bottom Using that for collision will give you the y as the least penetrating axis ...


0

Problems like these are common with new collision detection methods. I don't know too much about your current collision setup, but here is how it should go: First off, make these variables: Make a X and Y velocity Make a Gravity Make a jumpSpeed Make a isJumping Second off, make a timer to calculate the delta to affect the velocity of the object. ...


0

I see several things wrong with your code. However, before trying to list them here, let me just show how I would rewrite your main loop: // reset acceleration to default value acceleration.set(0, 0); // or, equivalently, acceleration.mult(0); // adjust acceleration based on keys pressed if (keys.up) { acceleration.add(0, 0.001); } if (keys.down) { ...


1

First, you shouldn't be hard-coding numbers like your acceleration. Numbers like these, which need to be fine tuned, should be variables that can be easily tweaked, either in one-place or dynamically using a slider or somesuch during testing. Second, from what I understand (of your comment to MagiSun), your problem with the acceleration giving you odd ...


1

In regards to this comment by OP: The problem is the resulting behavior, where the object continues to move up for example, even if the down key is pressed. It eventually changes direction but by then it's at nearly uncontrollable speeds. That is how velocity and acceleration work. You are simply providing the user with acceleration increments that ...


0

So, the .add method doesn't take negative numbers? If it does, it's just a matter of adding a negative acceleration to velocity. Otherwise, you really have no choice but to check. EDIT: I think I understand your problem now. Vectors can't be negative correct? If so, you'd probably be better off having acceleration be two scalars. This way, I assume they ...


0

Have you thought about adding negative velocity and using a ternary statement to decide what to add? if(keys.up != keys.down) { acceleration.add(0, keys.up ? 0.001 : -0.001); velocity.add(acceleration); location.add(velocity); } EDIT: What platform are you using? I've never seen a vector class that couldn't go negative.


4

After some more research I found out it's a Pinhole Camera Model. It is supposed to model a real camera. There is a nice description here: http://www.epixea.com/research/multi-view-coding-thesisse8.html What I was having trouble understanding was that I need some sort of projection plane. If there is no projection plane, all pixels would basically meet in ...


1

I found the problem. First I want to say, Jimmy's answer was useful advice, and I would recommend following it (having everything in radians). That being said, the problem was incorrect use of atan. Atan has quadrant-case issues, which I did not account for. This can be fixed by using atan2, which was made with that purpose in mind, or manually doing it. ...


3

It is a perspective projection, but those elements alone do not define the field of view. This article covers more of the basics of the components of a projection. http://msdn.microsoft.com/en-us/library/aa916436.aspx


1

You know the length going from the red line to the top of the blue line, right? Then you can apply some basic trigonometry. The blue line and the red line are the legs of a right triangle. Your desired line from the camera to the red line in the direction of the raycast is the triangle's hypotenuse (origin at the camera): Given an angle, theta between the ...


1

You can use Physics.SphereCast instead of RayCast. This allow you to perform queries of the intersection of a sphere sweeped along a given direction instead of single ray, allowing a more tolerant collision detection. Assign at least two different layers to the plane and the GameObjects under it, in order to exclude the plane from the query.


1

The dot product of the each face's normal with the vector from the face to the light position should distinguish which faces are front/back.


0

Instead of using Linecast, which, if I understand correctly, you use now, I'd suggest Raycast function, where the length of the direction vector doesn't matter. (By the mathematical definition, ray doesn't have an end.) If you want to be able to select a specific type of objects, it usually makes sense to assign these objects to a specific layer in unity and ...


3

This answer still ignores the attempt to use matrix rotation, but I realized that there was a simple yet general solution. First, assuming that the shape is encoded as coordinates of blocks in a grid, you have an arbitrary shape containing blocks with coordinates in the X and Y axes from 0 to n, where n+1 is the maximum size of a block (traditional Tetris ...


2

You are experiencing a 2D version of a common rookie 3D mistake: order of transformation matters. Matrix multiplication is not commutative, i.e. A * B is different from B * A. If you translate the Earth to its correct orbital radius before you rotate it according to the 24 hour clock, you will cause the earth to move along its orbital path (rotating a ...


4

you can concatinate 3 matrices first a translation to put 1,1 at 0,0, then the rotation and then translate 0,0 back to 1,1 if you use affine transformation matrices this is easy [1,0,-1][0,1,-1][0,0,1] * rotationMatrix * [1,0,1][0,1,1][0,0,1] if you don't use affine transformations then just subtract 1,1 on each point then rotate around 0,0, then re-add ...


0

I understand your problem to be this: You want to know from your Actor where the mouse is so that you can point in roughly that direction. In particular, you are limited to 8 facings. You can get most of where you want to go with determining the angle from point a to point b using Math.atan2, and then by changing to range from [0..2*PI) to [0..8). double ...


6

Two parts: 1. coordinate systems for angles can be...finicky. 2. You don't really need degrees for anything, with the possible exception of outputting their value to the user interface. Coordinate system angles So you want an angle from "North", and judging from your example math, that means the -Y direction (in sprite coordinates with the origin in the ...


1

I see a few potential gaps in your methods. One might be that you are using (presumably) constant axes for your aAxis calculation, xAxis and yAxis. I would guess those are the absolute world axes X and Y. That might be ok, if your specific scenario only uses planes oriented to X or Y. That's where you go awry. To rotate from one direction to another, ...



Top 50 recent answers are included