• Content count

  • Joined

  • Last visited

Community Reputation

294 Neutral

About ryt

  • Rank
  1. You do not need to free Bar since it is in declared in it and when you free Foo it gets removed automatically as Hodgman sad. If you create Bar in Main() it gets created on stack in this function and its removed automatically as you leave the function since stack on this function no longer exists. Similar is with the heap. But you need to remove it manually and when you do its all contents is removed.
  2. In C# in my base class Weapon I have declared a enum Firestate like: enum Firestate { Fire }; public class Weapon : MonoBehaviour { public Firestate firestate; }; And in a inherited class Gun I use that enum. But I get error CS0052: Inconsistent accessibility: field type 'Firestate' is less accessible than field 'Weapon.firestate'. When I remove public from firestate there is no error but then I cant use it in Gun since it is private.
  3. I agree with Nypyren. In some languages like C/C++ switch statements can be really fast. If you look at assembly code and your switch has like 1000 case statements in switch the code goes immediately to the desired case where in if else statements the code has to go trough every one to get to the desired one.
  4. How do you write variables for math names ? For vectors for example I sometimes append v like vLocalPosition. But for some common vectors I use names like pos, dir, dist. Also for coords I sometimes use forward, up, right. For matrices I append m in front or try to use a single uppercase letter like M.   How do you write names for transformations and rotations ? Names like transformAirplane or rotationCar seem a little cumbersome.
  5. That looks interesting. I did not know abaut corutines. In FSM for states I used enums and I would switch to a new state trough case statements. But I think functions could be also part of a state so functions could have the same name as a state. So if we need to switch to another state without using while we could just call another state function.
  6. I was building a finite state machine where I don't need a while statement but instead I just needed to switch to another state right after the first one finished. How would you transform the current code to put it out in a function ?
  7. I didn't know that. It looks like an old basic code . Is this a good coding practice ?
  8. Probably I asked the question wrong so it is misunderstood. What I actually wanted was to jump from one case statement to another case statement in one switch like: switch(somevalue) { case somevalue1: Function1(); break; case somevalue2: Function2(); break; } So for example that the code jumps from case somevalue1 to case somevalue2 without leaving the switch statement. But in C# we must have a break I think. Anyway I would like to jump to somevalue2 without deleting the break.
  9. Is it possible to jump from a switch statement to another switch statement without leaving the current switch in C# ?
  10. Colliding position

    I don't understand. Why we should take T0 = T1 that is compute it for some T. The two objects will have the same position and it will take different times to get there. That is if first object travels faster or is closer to the collision point than obviously T0 < T1.   Why did you took the Dot and normalized the vectors ?
  11. Colliding position

    Well my original question was about how to deal with the situation when we have vector division. In this case I took the magnitude of resulting vectors like:   t2 = |v1 * t1 + p1 - p2| / |v2|   So I wonder if this is the right way to use the magnitude and to get time t2 ?   In my example the two objects always collide since their final positions are same like p1 = p2 where p1 is final position of first object and p2 is final position of second object. If first object has some speed at some time t1 will arrive at position p1. So if their final positions of two objects are the same p2 is also known and we can find v2 and t2. If we set v2 to some speed and direction all we need to find is t2. This is the time that is in last equation. I made a mistake in the original post. I meant to say p1 = p2.
  12. Colliding position

    I have two objects and I want to find when will they collide. Lets say first target has position p0, velocity v0 and the time it will arrive at desired position is t0. Similar for the second target it has position p1, velocity v1 and the time t1. The general formula for speed with constant velocity is:   p = v*t + p0   So if we try to find their colliding position p0 and p1 should be equal at desired time so p0 = p1.   v1 * t1 + p1 = v2 * t2 + p2   t2 = v1 * t1 + p1 - p2 / v2   t2 is the time that will second object arrive at colliding position. I wonder how we can calculate this ? On the right hand side of last equation we have vector division. So since t2 is a scalar on the right hand side there also must be a scalar. So I think we should take the magnitude of vectors on right side and divide them. What to do in these situations when we have a division of two vectors ? Is this approach correct one ?