• 0

    posted a message on Need help with University Program coding!

    Hi Forum!

    So we are asked to create a program that simulates cue balls hitting eachother, combined from various sniplets of coding, compiled in MatLabs. Now I am asked to introduce the element of friction to the table. So the balls must lose speed over time if they are moving, bringing them to a halt. I thought about doing it like this:

    If speed > 0 then set speed = speed - speed*0.90

    At first I wanted to just say speed = speed * 0.90 but this would never bring the balls to a complete stop, so I figured I need a logiccase to see if they are moving (Maybe I need a 2nd if inside, saying if speed <0 then set speed = 0, to stop the ball if the speed is now below zero?) Anyway here is the code, I am not sure how the coding of MatLab works, I tried copypasting syntax but i keep getting a prgoram crash.

    % Program Desc.: The program will create a virtual simulation of cue balls on a pool table.
    
    clear all; clf;                     % Resets parameters
    
    % [Region] Define global variables
    table = [2.54, 1.27];               % Size of virtual table [meters]
    dt = 0.01;                          % Time interval between calculations [seconds]
    time = 10;                          % Time to run simulation [seconds]
    % [Region] Define global variables
    
    % [Region] Initial ball parameters
    balls(1).pos = [0.4, 0.6];          % Ball no. 1 initial transform from bottom-left [meters]
    balls(1).v = [0, 0];                % Ball no. 1 initital velocity [m/s]
    balls(1).r = 0.05;                  % Ball no. 1 initial radius for impact calculations [meters]
    balls(1).color = 'green';           % Ball no. 1 initial color.
    
    balls(2).pos = [table(1)-0.4 0.6];  % Ball no. 2 initial transform from bottom-left [meters]
    balls(2).v = [0, 0];                % Ball no. 2 initital velocity [m/s]
    balls(2).r = 0.05;                  % Ball no. 2 initial radius for impact calculations [meters]
    balls(2).color = 'red';             % Ball no. 2 initial color.
    
    balls(3).pos = [0.25, 1];           % Ball no. 3 initial transform from bottom-left [meters]
    balls(3).v = [6, -1.8];             % Ball no. 3 initital velocity [m/s]
    balls(3).r = 0.05;                  % Ball no. 3 initial radius for impact calculations [meters]
    balls(3).color = 'blue';            % Ball no. 3 initial color.
    % [Region] Initial ball parameters
    
    
    
    for t = 0:dt:time
        for a = 1:length(balls)
           
            % [Region] Update position
            % balls(a).pos = balls(a).pos + balls(a).v .* dt;     % Update transform from old transform + current speed * passed time interval.
            balls(a).pos = balls(a).pos + balls(a).v .* dt;
    
    NEW CODE HERE?????
    
            % [Region] Update position
            
            
            % [Region] Check for collision with wall
            if balls(a).pos(1)-balls(a).r <= 0 ...              % Compare (1) coordinate of transform to radius of current transform.
                    || balls(a).pos(1)+balls(a).r >= table(1)   % Compare (1) coordinate of transform to table variables (1) coordinate.
                balls(a).v(1) = -balls(a).v(1);                 % If True: Change velocity to reverse direction for (1) coordinate.
            end
            if balls(a).pos(2)-balls(a).r <= 0 ...              % Compare (2) coordinate of transform to radius of current transform.
                    || balls(a).pos(2)+balls(a).r >= table(2)   % Compare (2) coordinate of transform to table variables (2) coordinate.
                balls(a).v(2) = -balls(a).v(2);                 % If True: Change velocity to reverse direction for (2) coordinate.
            end
            % [Region] Check for collision with wall
            
            % [Region] Check for collision with balls
            for b = a+1:length(balls)
                if norm(balls(b).pos - balls(a).pos) <= balls(b).r + balls(a).r
     
                    % Calculate unit normal
                    un = (balls(b).pos - balls(a).pos) ./ norm(balls(b).pos - balls(a).pos);
                    ut = [-un(2), un(1)]; % Unit tangent
                    % Project velocity vectors into (normal,tangent)-coordinats
                    v_an = dot(un,balls(a).v);
                    v_at = dot(ut,balls(a).v);
                    v_bn = dot(un,balls(b).v);
                    v_bt = dot(ut,balls(b).v);
                    % Find velocities after collision
                    v_anp = v_bn.*un;
                    v_atp = v_at.*ut;
                    v_bnp = v_an.*un;
                    v_btp = v_bt.*ut;
                    % Add up the components for the resulting velocity
                    balls(a).v = v_anp + v_atp;
                    balls(b).v = v_bnp + v_btp;
                end
            end
            % [Region] Check for collision with balls
        end
        
        show(table,balls)
        pause(dt)
    end
    
    Posted in: Off-Topic
  • 0

    posted a message on Idea: Tamachoti / Companion - Plugin

    I wanted to create this, but never really had the time.

    A plugin that any other custom map and just copy into their map, to give some extra fun and played time. The plugin should allow the player to get a small companion critter to follow him around, without it affecting gameplay. Then in a sims/tamachoti style the player should be able to interact with his pet in various ways, trying to keep the pet happy. Unlockable pets as the player spends more time with a pet active. Cross map stats, meaning the shared bank file would mean no matter what custom game you play (that supports it) you can bring your pet into.

    I already created a large amount of the code, if anyone want to take over, or create this.

    Posted in: Map Suggestions/Requests
  • 0

    posted a message on Dialog Creator LF WORK

    @Juxtapozition: Go

    Indeed. Send some information, texts, themes, and what functions you want in a PM and I will get on it.

    Posted in: Team Recruitment
  • 0

    posted a message on Dialog Creator LF WORK

    I'm looking for some development above mid-way (reads as no new project startups), and I am not looking to make standard dialog windows, but menus where I am allowed to use custom art work and sound effects.

    I can create in-game menus, main menus, custom art, display windows, intro animations. Everything fit to order. My coding is very clean, understandable and comes with complete comments for re-fitting.

    Random two videos of some previous work, both without that much custom art though. More can be showcased upon request.

    Posted in: Team Recruitment
  • 0

    posted a message on Both players press the dialog button

    @jmac321wky: Go

    That will make a long and boring wait, if there's only one player. While he waits for the none exisitng player two to press.

    Posted in: Triggers
  • 0

    posted a message on Galcon Confusion

    Don't know if there's a name for it. I mean, the game is based on Galcon Fusion, that came out in year.. err.. DOS times.. I think if you watch my replay side by side to the galcon fusion one, they are pretty similar. Anyway discarded any follow up on this, so it's dead in the water but finished.

    Posted in: Map Feedback
  • 0

    posted a message on Galcon Confusion

    Just finished my map, to an extend where I feel it wasn't what I wanted to make, but I finished it anyhow. The game won't be updated or progressed and are only released for lower pages on EU, nothing fancy. None the less, here's a gameplay video of it. It's based on Galcon Fusion. You capture planets, to produce ships that you use to capture more planets. It's as simple as it gets.

    Posted in: Map Feedback
  • 0

    posted a message on Blizzard sees no problem with popularity system?

    Problem 1: Their map is so boring and uninteresting. Problem 2: They made it so melee maps, get on the custom map top 10 list, if enough people play them. Problem 3: People play what's on page 1. Page 1 gets more hits. Nothing changes. Problem 4: Using fun or not will result in hourlong que, cuz NOONE ELSE think it's fun. Problem 5: You can never get your map up played, without bugging your friends. Problem 6: I'm playing the games on page 1, and contributing to the problem.

    Ssly.. just let people bookmark a game if they like it, then every week give top page maps a cooldown period of a week or so and reset their map pop.. if people liked it when it was up, they would bookmark it and play, and when it gets of cooldown, it would rise fast enough

    Posted in: General Chat
  • 0

    posted a message on Despawning unit

    Curious about the "after exisiting orders" - When I do set patrol replace current, then add another line, stop after existing orders, the unit instantly stops and doesn't execute the patrol first, at first I thought patrol was accepted as done asap it was set, but then I tried "move" then "Stop" unit stil instantly stops. What's wrong?

    Posted in: Triggers
  • 0

    posted a message on Avoid Unit Entering Region eating my created units

    @DeProgrammer: Go

    Works. Thanks a lot.

    If you don't mind - it's been quite a while since I've used the editor so sort of rusted on some points, especially the data editor. [1] Solved. [2] is there a way for me to remove the rally point set from a command center. Like reset the line it creates when you right click the rally. It sets the rally, and then I'd like it to remove it. And [3] how do I change the rally point ability, to ONLY being able to target buildings, and not points on the ground, or units and [4] EDIT: Solved.

    Thanks a lot.

    Posted in: Triggers
  • 0

    posted a message on Avoid Unit Entering Region eating my created units

    Yo!

    So I have two regions that both have a trigger that removes any units that enter that region. This works so that when the unit walks from one region into the other it's then removed and visa versa if you enter the first region. But the problem is I also try to spawn the walking unit inside one of the regions, and tell him to move to the other region - The unit created is spawned inside one of the regions depending on choise.

    But I'm coming short on that, cuz' asap he is created that triggers the event that he actually just moved into the region, and then instantly removes him.

    Is there a way for me to spawn a unit inside a region without it triggering that the spawned unit, is actually entering the first region. I thought about creating a spawn point outside the region but that won't work. I also thought about using a unit group and a timer like a "invurnability period" but that's massive overload.

    Any ideas - if anyone got like an ich about it, I'll be happy to PM triggers for more details.

    Posted in: Triggers
  • 0

    posted a message on Need help making an action

    Hi World,

    I am looking for an effecient way of attaching an attack to a building. When you have the building selected and right click on an enemy unit it then creates some units (eg. scvs) and orders them to attack. Preferably I would like to run a trigger when used, so I can control how many units are spawned and change the variables accordingly.

    Posted in: Data
  • 0

    posted a message on Teams in triggers!

    @Tekaichi: Go

    Where did you find that one, whats the syntax.

    Posted in: Triggers
  • 0

    posted a message on Teams in triggers!

    I'm in a pickle here.

    I have two teams; one on each side. When the players select a dialog item, it then spawns an unit for them and issue a command to that unit, but how do I determin what team the players are on. I was thinking of having two seperate triggers, one for each team so I could just adjust the spawn and attack order to the correct places, but how do I actually find out what player is on what team, so I can send his units the right place. I can't use "Triggering player == 1" or so, for that wont work if it's a 2v2 or 3v3 and not 4v4 ..

    And same with the units already on the field, I dont want to force split the teams set in lobby by sending one that way, one that way, one that way....

    Posted in: Triggers
  • 0

    posted a message on Proof that Gravity is scripted

    No,m not really.

    Look at the head of the snowman, it is clearly that the worlds gravity is on a loop trigger and not constant.

    Check every 10 seconds of [real life] time.

    Posted in: Off-Topic
  • To post a comment, please or register a new account.