Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-04-2007, 01:22 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Object Physics

Well, after years of always wanting to do it, I finally have! I made physics for NPC objects, with some advice from a few people. Now, it may take some editing on your part to work for your server, but that shouldn't be too hard.
PHP Code:
/*Set this.weight and this.width/this.height (in pixels) before
joining the class*/
function onCreated() {
  
this.anglex this.angley NULL;
  
this.velocity this.dist this.momentum NULL;
  
this.distgone this.time this.timetotal NULL;
  
this.this.width/16;
  
this.this.height/16;
}
/*You'll probably have your own function for when the object is hit,
hence you'll probably need your own calculations for velocity and distance.*/
function onActionHit(damageaccuracyeffectsaccpxpy) {
  
this.distgone 0;
  
this.angle getangle(px-this.x,py-this.y);
  if (
this.angle degtorad(180))
    
this.angle -= degtorad(180);
  else 
this.angle += degtorad(180);
  
this.velocity = ((damage*4.45)/this.weight)*.05;
  
temp.friction this.weight/damage;
  if (
temp.friction>=1this.dist 0;
  else 
this.dist temp.friction;
  
onTimeOut();
}
function 
onTimeOut() {
  if (
this.distgone this.dist) {
    
temp.this.x+(this.w/2); temp.this.y+(this.h/2);
    
temp.dx temp.x+cos(this.angle)*((this.velocity/3)*4);
    
temp.dy temp.y-sin(this.angle)*((this.velocity/3)*4);
    if (
temp.dx temp.xtemp.dx += 2;
    if (
temp.dy temp.ytemp.dy += .5;
    else if (
temp.dy temp.ytemp.dy += 1.75;
    if (!
onwall(temp.dxtemp.y))
      
this.+= cos(this.angle)*this.velocity;
    else
      
this.angle pi this.angle;
    if (!
onwall(temp.x,temp.dy))
      
this.+= -sin(this.angle)*this.velocity;
    else
      
this.angle = -this.angle;
    
this.distgone += this.velocity;
    
this.velocity = (this.velocity/7)*6;
    
setTimer(0.05);
  }

Enjoy
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts

Last edited by coreys; 11-04-2007 at 01:33 AM..
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 07:34 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.