Hello I've been trying to make a game for school and every time I add collision detection code to my project my object which is a coin keeps spazzing out without the player even touching out. The coin just goes all over the screen randomly with the player having any interactions with. I've tried removing the random spawn of the coin but the score keeps updating even without the player being near the coin
I have attached a file and I was wondering how I would use code tags, sorry I'm new to posting on forums
Coin keeps spazzing out when collision code is added
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Coin keeps spazzing out when collision code is added
- Attachments
-
- FInal Project.zip
- (1.68 MiB) Downloaded 44 times
Re: Coin keeps spazzing out when collision code is added
Hi
Your coin is too big and so it collides every frame.
love.graphics.getWidth() / Height() get the size of the window.
I guess you will want to use https://love2d.org/wiki/Texture:getWidth but for testing I just put fixed numbers:
Your coin is too big and so it collides every frame.
love.graphics.getWidth() / Height() get the size of the window.
I guess you will want to use https://love2d.org/wiki/Texture:getWidth but for testing I just put fixed numbers:
Code: Select all
function Coin:new()
self.image = love.graphics.newImage('sprites/coin.png')
self.x = 300
self.y = 300
self.speed = 0
self.w = 50--love.graphics.getWidth()
self.h = 50--love.graphics.getHeight()
Re: Coin keeps spazzing out when collision code is added
To use code tags, you write:
[code]
the code here
[/code]
Re: Coin keeps spazzing out when collision code is added
thanks i usedknorke wrote: ↑Sat May 06, 2023 10:14 am Hi
Your coin is too big and so it collides every frame.
love.graphics.getWidth() / Height() get the size of the window.
I guess you will want to use https://love2d.org/wiki/Texture:getWidth but for testing I just put fixed numbers:Code: Select all
function Coin:new() self.image = love.graphics.newImage('sprites/coin.png') self.x = 300 self.y = 300 self.speed = 0 self.w = 50--love.graphics.getWidth() self.h = 50--love.graphics.getHeight()
Code: Select all
self.image:getWidth() and self.image:getHeight()
Re: Coin keeps spazzing out when collision code is added
Ah yes. You need to do the same fix for the player's dimensions as well.
In function Player:new()
In function Player:new()
Re: Coin keeps spazzing out when collision code is added
Thanks for your help
Who is online
Users browsing this forum: Bing [Bot] and 4 guests