• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

why is this value shrinking?

Dubbsta

Active member
Joined
Jul 13, 2017
Messages
208
im copying nature of code physics accumulation and using a wind vector for 2 objects but when they share the vector they both move the same pace
if i use seperate vectors for each object the second objects vector keeps shrinking. the only solution i found was to constantly update the second wind:vector.x = .3
can someone tell my why the second value keeps shrinking and how to share the same value thx
Cerberus:
Class Vector

 Field x:Float
 Field y:Float
 
 
        
            Method New(x:Float=0,y:Float=0)
                Self.x = x
                Self.y = y
            End
            
            
            Method set:Void(x:Float,y:Float)
                Self.x = x
                Self.y = y
            End
            
            
            Method add:Void(v:Vector)
                x += v.x
                y += v.y
            End
            
            
            Method sub:Void(v:Vecto)
                x -= v.x
                y -= v.y
            End
            
            Method div:Void(num:Float)
                x /= num
                y /= num
            End
            
            Method mult:Void(v:Vector)
                x *= v.x
                y *= v.y
            End
            
            Method mag:Void(num:Int)
                x *= num
                y *= num
            End
            
            Method normalize:Void()
                x /= x
                y /= y
            End
            
            
            Method dot:Void()
            
            End
            
            Method cross:Void()
            
            End
End




Class Ball
 Field pos:Vector
 Field vel:Vector
 Field accel:Vector
 Field size:Int = 10
 Field mass:float
 Field f:Vector
 
 
         Method New(x:Float,y:Float,mass:Float)
             pos = New Vector(x,y)
             vel = New Vector()
             accel = New Vector()
              f = New Vector()
             Self.mass = mass
         End
        
        
        
         Method applyforce:Void(force:Vector)
                f  = force
            
             f.div(mass)
            
             accel.add(f)
         End
        
        
        
         Method update:Void()
        
             vel.add(accel)
                    
            
             pos.add(vel)     
              
            
             accel.mag(0)     
         End
        
        
        
        
        
         Method edges:Void()
             If pos.y > DeviceHeight() - mass * size/2
                 pos.y = pos.y
                 vel.y *= -1
             Elseif
                 pos.y < 0 + mass * size/2
                     pos.y = pos.y
                     vel.y *= -1
             End
            
             If pos.x > DeviceWidth() - mass * size/2
                 pos.x = pos.x
                 vel.x *= -1
             Elseif
                 pos.x < 0 + mass * size/2
                    
                 vel.x *= -1
                 pos.x = pos.x
             End
         End
        
        
         Method draw:Void()
             DrawCircle(pos.x,pos.y,mass * size)
              
         End
End


 

Class gamename Extends App
 
 Field ball:Ball
 Field ball2:Ball
 
 Field wind:Vector
 Field wind2:Vector 'i only want to use one vector'
 Field grav1:Vector
 Field grav2:Vector
 
 
        Method OnCreate:int()
            SetUpdateRate(60)
            
            
            cir = New MakeCircle(150,150,70)
            ball = New Ball(100,50,1)
            ball2 = New Ball( 200,50,5)
            wind = New Vector(.3,0)
            wind2 = New Vector(.3,0)
            grav1 = New Vector(0,0.2)
            grav2 = New Vector(0,0.2)
            time = New Time()
            
            Return 0
        End
        
        
        Method OnUpdate:int()
            grav1.y *= ball.mass
            grav2.y *= ball2.mass
            
            ball.applyforce(grav1)
            ball2.applyforce(grav2)
            
            'wind2.x = .3 'solution that works but doesnt seem right'
            
            If MouseDown(MOUSE_LEFT)
            
                ball.applyforce(wind)
                
                'ball2.applyforce(wind) this will change both values'
                
                ball2.applyforce(wind2) 'this value keeps changing'
            End
            
            ball.update()
            ball2.update()
            ball.edges()
            ball2.edges()
            time.getsecs()
            Return 0
        End
        
        
        Method OnRender:int()
            Cls 0,0,0
            cir.draw()
            ball.draw()
            ball2.draw()
            time.draw()
            'DrawText(ball.f.y,10,10)
            DrawText(ball.f.x,10,20)
            DrawText(ball.vel.y,10,30)
            DrawText(ball2.f.x,10,40)
            Return 0
        End
End





Function Main:int()

    New gamename()
    
    Return 0
    
End
 
forgot to import mojo and deleted a couple of lines, this should work
thx
seems to keep dividing...

Cerberus:
Import mojo


Class Vector

Field x:Float
Field y:Float


       
            Method New(x:Float=0,y:Float=0)
                Self.x = x
                Self.y = y
            End
           
           
            Method set:Void(x:Float,y:Float)
                Self.x = x
                Self.y = y
            End
           
           
            Method add:Void(v:Vector)
                x += v.x
                y += v.y
            End
           
           
            Method sub:Void(v:Vecto)
                x -= v.x
                y -= v.y
            End
           
            Method div:Void(num:Float)
                x /= num
                y /= num
            End
           
            Method mult:Void(v:Vector)
                x *= v.x
                y *= v.y
            End
           
            Method mag:Void(num:Int)
                x *= num
                y *= num
            End
           
            Method normalize:Void()
                x /= x
                y /= y
            End
           
           
            Method dot:Void()
           
            End
           
            Method cross:Void()
           
            End
End




Class Ball
Field pos:Vector
Field vel:Vector
Field accel:Vector
Field size:Int = 10
Field mass:float
Field f:Vector


         Method New(x:Float,y:Float,mass:Float)
             pos = New Vector(x,y)
             vel = New Vector()
             accel = New Vector()
              f = New Vector()
             Self.mass = mass
         End
       
       
       
         Method applyforce:Void(force:Vector)
                f  = force
           
             f.div(mass)
           
             accel.add(f)
         End
       
       
       
         Method update:Void()
       
             vel.add(accel)
                   
           
             pos.add(vel)    
             
           
             accel.mag(0)    
         End
       
       
       
       
       
         Method edges:Void()
             If pos.y > DeviceHeight() - mass * size/2
                 pos.y = pos.y
                 vel.y *= -1
             Elseif
                 pos.y < 0 + mass * size/2
                     pos.y = pos.y
                     vel.y *= -1
             End
           
             If pos.x > DeviceWidth() - mass * size/2
                 pos.x = pos.x
                 vel.x *= -1
             Elseif
                 pos.x < 0 + mass * size/2
                   
                 vel.x *= -1
                 pos.x = pos.x
             End
         End
       
       
         Method draw:Void()
             DrawCircle(pos.x,pos.y,mass * size)
             
         End
End




Class gamename Extends App

Field ball:Ball
Field ball2:Ball

Field wind:Vector
Field wind2:Vector 'i only want to use one vector'
Field grav1:Vector
Field grav2:Vector


        Method OnCreate:int()
            SetUpdateRate(60)
           
           
           
            ball = New Ball(100,50,1)
            ball2 = New Ball( 200,50,5)
            wind = New Vector(.3,0)
            wind2 = New Vector(.3,0)
            grav1 = New Vector(0,0.2)
            grav2 = New Vector(0,0.2)
           
           
            Return 0
        End
       
       
        Method OnUpdate:int()
            grav1.y *= ball.mass
            grav2.y *= ball2.mass
           
            ball.applyforce(grav1)
            ball2.applyforce(grav2)
           
            'wind2.x = .3 'solution that works but doesnt seem right'
           
            If MouseDown(MOUSE_LEFT)
           
                ball.applyforce(wind)
               
                'ball2.applyforce(wind) this will change both values'
               
                ball2.applyforce(wind2) 'this value keeps changing'
            End
           
            ball.update()
            ball2.update()
            ball.edges()
            ball2.edges()
         
            Return 0
        End
       
       
        Method OnRender:int()
            Cls 0,0,0
           
            ball.draw()
            ball2.draw()
           
            'DrawText(ball.f.y,10,10)
            DrawText(ball.f.x,10,20)
            DrawText(ball.vel.y,10,30)
            DrawText(ball2.f.x,10,40)
            Return 0
        End
End





Function Main:int()

    New gamename()
   
    Return 0
   
End
 
Last edited:
Did you notice, that you are working with references i.e. pointers in applyforce() and not values?
So f = force sets f to the handle of force and with f.div you change the values in force alias wind indirectly.

I did not read through all your code, so maybe I don't adress your problem correctly.
 
thx Phil7 that was the problem. i was sure by doing that i copied over the values...
that was really driving me crazy o_O
 
Back
Top Bottom